diff --git a/connect_switch.ino b/connect_switch.ino index 108fe51..cf8c323 100644 --- a/connect_switch.ino +++ b/connect_switch.ino @@ -16,16 +16,17 @@ struct arrow { int state; }; -struct button { +struct ButtonInfo { int pinNumber; bool prev; bool current; + Button buttonSymbol; }; struct arrow arrowTable[4]; +#define ButtonInfoTableSize 2 +struct ButtonInfo buttonInfoTable[ButtonInfoTableSize]; -struct button bButton; -struct button plusButton; void perms() { if(val == 0){ @@ -51,6 +52,14 @@ void button() { } */ +void setupButton(ButtonInfo *but, int pinNumber, Button buttonSymbol) { + but->pinNumber = pinNumber; + but->buttonSymbol = buttonSymbol; + pinMode(pinNumber, INPUT_PULLUP); + but->prev = 1; + but->current = 1; +} + void setup() { table[0] = 1; @@ -60,6 +69,10 @@ void setup() MsTimer2::set(1, perms); MsTimer2::start(); + setupButton(&(buttonInfoTable[0]), 3, Button::B); + setupButton(&(buttonInfoTable[1]), 15, Button::PLUS); + +/* bButton.pinNumber = 3; pinMode(bButton.pinNumber, INPUT_PULLUP); bButton.prev = 1; @@ -69,7 +82,7 @@ void setup() pinMode(plusButton.pinNumber, INPUT_PULLUP); plusButton.prev = 1; plusButton.current = 1; - +*/ pinMode(2, INPUT_PULLUP); @@ -87,6 +100,18 @@ void setup() } +void handleButtonInput(ButtonInfo *but){ + but->current = digitalRead(but->pinNumber); + + if(but->prev == 1 && but->current ==0 ){ + SwitchControlLibrary().PressButton(but->buttonSymbol); + } + else if(but->prev == 0 && but->current ==1 ) { + SwitchControlLibrary().ReleaseButton(but->buttonSymbol); + } + + but->prev = but->current; +} void loop() { @@ -101,7 +126,11 @@ void loop() prevVal = val; +for(int i=0; i