keyboard - How can I use a toggle switch as a momentary switch on my arduino? -


i have specific switch need use , happens toggle. problem is, need send keyboard stroke computer time button pushed on or off. tried 1 modification of basic example on arduino website, isn't working me:

const int buttonpin = 2;  // number of pushbutton pin int prior = 0;  int buttonstate = 0;      // variable reading pushbutton status  void setup() {     pinmode(ledpin, output);     pinmode(buttonpin, input);     keyboard.begin(); }  void loop()  {     prior = buttonstate;       buttonstate = digitalread(buttonpin);     if (buttonstate != prior) {            keyboard.write(32);     } } 

you can debug issue breaking 2 part. first debug whether able toggle of switch can switch led on/off whenever toggle switch (assuming leds working fine) in loop. once done. debug keyboard.write() send characters pc @ fixed delay may 1sec in loop. if both working fine above program might work. try adding delay after keyboard.write().


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -