added multiple games [broken]
This commit is contained in:
87
src/chainGame.cpp
Normal file
87
src/chainGame.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "chainGame.h"
|
||||
#include "Arduino.h"
|
||||
#include "buttons.h"
|
||||
|
||||
extern buttons button1;
|
||||
extern buttons button2;
|
||||
extern buttons button3;
|
||||
|
||||
|
||||
uint8_t patternIndex = 0;
|
||||
bool patternFlag = false;
|
||||
bool firstpattern = false;
|
||||
|
||||
uint8_t ledpattern[4][3] = {
|
||||
{1,0,0},
|
||||
{0,0,1},
|
||||
{1,0,0},
|
||||
{0,1,0},
|
||||
};
|
||||
int patternlength = sizeof(ledpattern)/sizeof(ledpattern[0]);
|
||||
|
||||
void nextPattern(void)
|
||||
{
|
||||
if (patternIndex < patternlength-1)
|
||||
{
|
||||
patternIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
patternIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleChainGame(void)
|
||||
{
|
||||
if (button1.state())
|
||||
{
|
||||
if (!patternFlag)
|
||||
{
|
||||
//button detected, increase pattern
|
||||
if(!firstpattern)
|
||||
{
|
||||
firstpattern = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextPattern();
|
||||
}
|
||||
|
||||
patternFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (button2.state())
|
||||
{
|
||||
if (!patternFlag)
|
||||
{
|
||||
if(!firstpattern)
|
||||
{
|
||||
firstpattern = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//second input, skip a pattern
|
||||
nextPattern();
|
||||
nextPattern();
|
||||
}
|
||||
patternFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (button1.state() | button2.state())
|
||||
{
|
||||
//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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user