fixes to chaingame
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
// extern c_button button3;
|
// extern c_button button3;
|
||||||
|
|
||||||
uint8_t patternIndex = 0;
|
uint8_t patternIndex = 0;
|
||||||
uint8_t nextPatternIndex = 1;
|
//uint8_t nextPatternIndex = 1;
|
||||||
bool patternFlag = false;
|
bool patternFlag = false;
|
||||||
bool firstpattern = false;
|
bool firstpattern = false;
|
||||||
e_ledcolor cheatbutton = NONE;
|
e_ledcolor cheatbutton = NONE;
|
||||||
@@ -41,20 +41,41 @@ void nextPattern(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResetChainGame(void)
|
||||||
|
{
|
||||||
|
patternIndex = 0;
|
||||||
|
patternFlag = false;
|
||||||
|
firstpattern = false;
|
||||||
|
cheatbutton = NONE;
|
||||||
|
cheatButtonFlag = false;
|
||||||
|
}
|
||||||
|
|
||||||
void HandleChainGame(void)
|
void HandleChainGame(void)
|
||||||
{
|
{
|
||||||
if (buttonIsPressed(ledpattern[patternIndex]))
|
if (buttonIsPressed(ledpattern[patternIndex]) && !cheatButtonFlag)
|
||||||
{
|
{
|
||||||
turnOnLed(ledpattern[patternIndex]);
|
turnOnLed(ledpattern[patternIndex]);
|
||||||
patternFlag = true;
|
patternFlag = true;
|
||||||
cheatbutton = NONE;
|
|
||||||
}
|
}
|
||||||
else if (buttonIsPressed(cheatbutton))
|
else if (buttonIsPressed(cheatbutton) && !patternFlag && !cheatButtonFlag)
|
||||||
{
|
{
|
||||||
turnOnLed(cheatbutton);
|
turnOnLed(cheatbutton);
|
||||||
cheatButtonFlag = true;
|
cheatButtonFlag = true;
|
||||||
}
|
}
|
||||||
else if (!anybutton())
|
|
||||||
|
if (!buttonIsPressed(ledpattern[patternIndex]))
|
||||||
|
{
|
||||||
|
turnOffLed(ledpattern[patternIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!buttonIsPressed(cheatbutton) && cheatButtonFlag)
|
||||||
|
{
|
||||||
|
turnOffLed(cheatbutton);
|
||||||
|
cheatButtonFlag = false;
|
||||||
|
cheatbutton = NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!anybutton())
|
||||||
{
|
{
|
||||||
turnOffAllLed();
|
turnOffAllLed();
|
||||||
if (patternFlag)
|
if (patternFlag)
|
||||||
@@ -62,76 +83,19 @@ void HandleChainGame(void)
|
|||||||
patternFlag = false;
|
patternFlag = false;
|
||||||
nextPattern();
|
nextPattern();
|
||||||
}
|
}
|
||||||
if(cheatButtonFlag)
|
|
||||||
{
|
|
||||||
cheatButtonFlag = false;
|
|
||||||
cheatbutton = NONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(buttonIsPressed(YELLOW2))
|
//check cheatbuttons
|
||||||
|
if (buttonIsPressed(YELLOW2) && (cheatbutton == NONE))
|
||||||
{
|
{
|
||||||
cheatbutton = YELLOW;
|
cheatbutton = YELLOW;
|
||||||
}
|
}
|
||||||
else if(buttonIsPressed(RED2))
|
else if (buttonIsPressed(RED2) && (cheatbutton == NONE))
|
||||||
{
|
{
|
||||||
cheatbutton = RED;
|
cheatbutton = RED;
|
||||||
}
|
}
|
||||||
else if(buttonIsPressed(GREEN2))
|
else if (buttonIsPressed(GREEN2) && (cheatbutton == NONE))
|
||||||
{
|
{
|
||||||
cheatbutton = GREEN;
|
cheatbutton = GREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (buttonIsPressed(YELLOW) | buttonIsPressed(RED) | buttonIsPressed(GREEN))
|
|
||||||
// {
|
|
||||||
// if (!patternFlag)
|
|
||||||
// {
|
|
||||||
// //button detected, increase pattern
|
|
||||||
// if (!firstpattern)
|
|
||||||
// {
|
|
||||||
// firstpattern = true;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// nextPattern();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// patternFlag = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (buttonIsPressed(RED))
|
|
||||||
// {
|
|
||||||
// if (!patternFlag)
|
|
||||||
// {
|
|
||||||
// if (!firstpattern)
|
|
||||||
// {
|
|
||||||
// firstpattern = true;
|
|
||||||
// nextPattern();
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //second input, skip a pattern
|
|
||||||
// nextPattern();
|
|
||||||
// nextPattern();
|
|
||||||
// }
|
|
||||||
// patternFlag = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (anybutton() && patternFlag)
|
|
||||||
// {
|
|
||||||
// //write pattern to the LEDs
|
|
||||||
// digitalWrite(LED1, ledpattern[patternIndex][0]);
|
|
||||||
// digitalWrite(LED2, ledpattern[patternIndex][1]);
|
|
||||||
// digitalWrite(LED3, ledpattern[patternIndex][2]);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// //leds off
|
|
||||||
// digitalWrite(LED1, 0);
|
|
||||||
// digitalWrite(LED2, 0);
|
|
||||||
// digitalWrite(LED3, 0);
|
|
||||||
// patternFlag = false;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
void HandleChainGame( void );
|
void HandleChainGame( void );
|
||||||
|
void ResetChainGame(void);
|
||||||
|
|
||||||
|
|
||||||
#endif //CHAINGAMEH
|
#endif //CHAINGAMEH
|
||||||
@@ -8,17 +8,9 @@
|
|||||||
#define CHANNELS 3
|
#define CHANNELS 3
|
||||||
#define SAMPLES 20
|
#define SAMPLES 20
|
||||||
|
|
||||||
extern ToggleButton button1;
|
|
||||||
extern ToggleButton button2;
|
|
||||||
extern ToggleButton button3;
|
|
||||||
|
|
||||||
extern std::vector<c_button *> buttonlist;
|
extern std::vector<c_button *> buttonlist;
|
||||||
|
|
||||||
unsigned int detectled[CHANNELS] = {0, 0, 0};
|
|
||||||
uint32_t detectledRaw[CHANNELS][SAMPLES];
|
|
||||||
const uint32_t inputs[CHANNELS] = {DETECT1, DETECT2, DETECT3};
|
|
||||||
const uint32_t leds[CHANNELS] = {LED1, LED2, LED3};
|
|
||||||
uint32_t sampleIndex = 0;
|
|
||||||
|
|
||||||
c_leds *ledlist_ptr;
|
c_leds *ledlist_ptr;
|
||||||
|
|
||||||
|
|||||||
10
src/main.cpp
10
src/main.cpp
@@ -7,8 +7,8 @@
|
|||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
#define TIMEOUT 15000 // 15sec * 1000ms
|
#define TIMEOUT 15000 // 15sec * 1000ms
|
||||||
#define GAMESELECTTIMEOUT 7000 // 7sec * 1000ms
|
#define GAMESELECTTIMEOUT 7000 // 7sec * 1000ms
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@@ -35,6 +35,8 @@ void HandleIdle(void)
|
|||||||
{
|
{
|
||||||
//prepare for next game
|
//prepare for next game
|
||||||
nextGame = ChainGame;
|
nextGame = ChainGame;
|
||||||
|
ResetChainGame();
|
||||||
|
turnOffLed(YELLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
//red button first released
|
//red button first released
|
||||||
@@ -42,6 +44,7 @@ void HandleIdle(void)
|
|||||||
{
|
{
|
||||||
//prepare for next game
|
//prepare for next game
|
||||||
nextGame = magicSwitchBoard;
|
nextGame = magicSwitchBoard;
|
||||||
|
turnOffLed(RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
//green button first released
|
//green button first released
|
||||||
@@ -49,6 +52,7 @@ void HandleIdle(void)
|
|||||||
{
|
{
|
||||||
//prepare for next game
|
//prepare for next game
|
||||||
nextGame = detectLED;
|
nextGame = detectLED;
|
||||||
|
turnOffLed(GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
//wait for all buttons to be switched off
|
//wait for all buttons to be switched off
|
||||||
@@ -62,7 +66,7 @@ void HandleIdle(void)
|
|||||||
void HandleGameSelectTimeout(void)
|
void HandleGameSelectTimeout(void)
|
||||||
{
|
{
|
||||||
uint64_t currentmillis = millis();
|
uint64_t currentmillis = millis();
|
||||||
if(buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN))
|
if (buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN))
|
||||||
//if (yellow && red && green)
|
//if (yellow && red && green)
|
||||||
{
|
{
|
||||||
//all buttons pressed, wait for next game
|
//all buttons pressed, wait for next game
|
||||||
|
|||||||
Reference in New Issue
Block a user