davidteensy
Member
Hello teensy gang!
I have a keyboard foot controller project that I have been working on, but I hit a problem... I want to have 12 buttons and two leds for each button, and then one other button (with one, or two, leds). The last button I want to act as a 'bank switch', so that it changes the functions of the other buttons.
put in a simpler way:
have two buttons and three leds.
if buttonbank has been pressed (turn on led2)
-press button1 and send keystroke 'A' and turn on led1
-press button1 again to send keystroke 'A' and turn off led1
else buttonbank has not been pressed (led2 off)
-press button1 again, send keystroke 'a' and turn on led3
-press again to send keystroke 'a' and turn off led3
seems simple enough, but so far I have not been able to do it.
I have written stable code for a button to turn on an led and send a keystroke, and then when pressed again turn off the led and send the keystroke again. perfect. but when I try to do the rest as described above -
but this doesn't work! currently the 'bank' switch doesn't work stabley, and the key switch seems to spit both of the letters out, or one, and turns on both, one, or none of the leds...seems like I am catching the code in parts of the loop..
let me know what your great minds think... maybe I need a different attack?
thanks
I have a keyboard foot controller project that I have been working on, but I hit a problem... I want to have 12 buttons and two leds for each button, and then one other button (with one, or two, leds). The last button I want to act as a 'bank switch', so that it changes the functions of the other buttons.
put in a simpler way:
have two buttons and three leds.
if buttonbank has been pressed (turn on led2)
-press button1 and send keystroke 'A' and turn on led1
-press button1 again to send keystroke 'A' and turn off led1
else buttonbank has not been pressed (led2 off)
-press button1 again, send keystroke 'a' and turn on led3
-press again to send keystroke 'a' and turn off led3
seems simple enough, but so far I have not been able to do it.
I have written stable code for a button to turn on an led and send a keystroke, and then when pressed again turn off the led and send the keystroke again. perfect. but when I try to do the rest as described above -
Code:
#include <Bounce.h>
Bounce button2 = Bounce(PIN_B2, 10);
Bounce button3a = Bounce(PIN_B3, 10);
Bounce button3b = Bounce(PIN_B3, 10);
int ledPin4 = PIN_B4;
int ledPin5 = PIN_B5;
int ledPin6 = PIN_B6;
int state2 = LOW;
int state3a = LOW;
int state3b = LOW;
int reading2;
int reading3a;
int reading3b;
int previous2 = HIGH;
int previous3a = HIGH;
int previous3b = HIGH;
long time = 0;
long debounce = 200;
void setup() {
pinMode(PIN_B2, INPUT_PULLUP);
pinMode(PIN_B3, INPUT_PULLUP);
pinMode(PIN_B4, OUTPUT);
pinMode(PIN_B5, OUTPUT);
pinMode(PIN_B6, OUTPUT); }
void loop() {
button2.update();
reading2 = digitalRead(PIN_B2);
if (reading2 == HIGH && previous2 == LOW && millis() - time > debounce)
{ if (state2 == HIGH) state2 = LOW;
else
state2 = HIGH;
time = millis(); }
digitalWrite(PIN_B5, state2);
previous2 = reading2;
if (state2 == LOW)
{
button3a.update();
reading3a = digitalRead(PIN_B3);
if (reading3a == HIGH && previous3a == LOW && millis() - time > debounce)
{ if (state3a == HIGH) state3a = LOW;
else state3a = HIGH;
time = millis(); }
digitalWrite(PIN_B4, state3a);
previous3a = reading3a;
if (button3a.fallingEdge())
{ Keyboard.print("b");
}
else (state2==HIGH)
{
button3b.update();
reading3b = digitalRead(PIN_B3);
if (reading3b == HIGH && previous3b == LOW && millis() - time > debounce)
{ if (state3b == HIGH) state3b = LOW;
else state3b = HIGH;
time = millis(); }
digitalWrite(PIN_B6, state3b);
previous3b = reading3b;
if (button3b.fallingEdge())
{ Keyboard.print("B");
}}}}
but this doesn't work! currently the 'bank' switch doesn't work stabley, and the key switch seems to spit both of the letters out, or one, and turns on both, one, or none of the leds...seems like I am catching the code in parts of the loop..
let me know what your great minds think... maybe I need a different attack?
thanks
Last edited: