added multiple games [broken]

This commit is contained in:
willem oldemans
2020-11-08 22:06:41 +01:00
parent a16ccf479d
commit 0123e4cc9f
20 changed files with 3951 additions and 73 deletions

87
src/chainGame.cpp Normal file
View 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;
}
}