diff --git a/src/buttons.cpp b/src/buttons.cpp index 8e6dfd8..574b73e 100644 --- a/src/buttons.cpp +++ b/src/buttons.cpp @@ -63,6 +63,19 @@ bool buttonIsPressed(e_ledcolor index) } } +bool buttonIsPressed(uint16_t index) +{ + c_button *thisbutton = getButton(index); + if (thisbutton == NULL) + { + return false; + } + else + { + return thisbutton->isPressed(); + } +} + bool buttonWasPressed(e_ledcolor index) { c_button *thisbutton = getButton(index); diff --git a/src/buttons.h b/src/buttons.h index cde0c13..3b93958 100644 --- a/src/buttons.h +++ b/src/buttons.h @@ -29,6 +29,7 @@ c_button *getButton(e_ledcolor index); std::vector* getButtonlist(void); bool buttonIsPressed(e_ledcolor index); +bool buttonIsPressed(uint16_t index); bool buttonWasPressed(e_ledcolor index); diff --git a/src/chainGame.cpp b/src/chainGame.cpp index 50e4739..a7200d8 100644 --- a/src/chainGame.cpp +++ b/src/chainGame.cpp @@ -2,30 +2,29 @@ #include "Arduino.h" #include "buttons.h" -// extern c_button button1; -// extern c_button button2; -// extern c_button button3; uint8_t patternIndex = 0; -//uint8_t nextPatternIndex = 1; bool patternFlag = false; bool firstpattern = false; -e_ledcolor cheatbutton = NONE; +//e_ledcolor cheatbutton = NONE; +uint16_t cheatbutton = 0; bool cheatButtonFlag = false; -// uint8_t ledpattern[4][3] = { -// {1, 0, 0}, -// {0, 0, 1}, -// {1, 0, 0}, -// {0, 1, 0}, -// }; -e_ledcolor ledpattern[4] = - { - YELLOW, - GREEN, - YELLOW, - RED}; +// e_ledcolor ledpattern[4] = +// { +// YELLOW, +// GREEN, +// YELLOW, +// RED}; + +uint16_t ledpattern[4] = +{ + 1, + 3, + 1, + 2 +}; int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]); @@ -86,16 +85,16 @@ void HandleChainGame(void) } //check cheatbuttons - if (buttonIsPressed(YELLOW2) && (cheatbutton == NONE)) + if (buttonIsPressed(1) && (cheatbutton == NONE)) { - cheatbutton = YELLOW; + cheatbutton = 1; } - else if (buttonIsPressed(RED2) && (cheatbutton == NONE)) + else if (buttonIsPressed(2) && (cheatbutton == NONE)) { - cheatbutton = RED; + cheatbutton = 2; } - else if (buttonIsPressed(GREEN2) && (cheatbutton == NONE)) + else if (buttonIsPressed(3) && (cheatbutton == NONE)) { - cheatbutton = GREEN; + cheatbutton = 3; } } \ No newline at end of file