modified games

This commit is contained in:
willem oldemans
2020-12-08 18:38:35 +01:00
parent 43fcb87efc
commit 32ae7afe35
9 changed files with 489 additions and 139 deletions

View File

@@ -1,22 +1,30 @@
#include "chainGame.h"
#include "Arduino.h"
//#include "JC_Button.h"
#include "buttons.h"
extern c_button button1;
extern c_button button2;
extern c_button button3;
// 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;
uint8_t ledpattern[4][3] = {
{1, 0, 0},
{0, 0, 1},
{1, 0, 0},
{0, 1, 0},
};
// 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};
int patternlength = sizeof(ledpattern) / sizeof(ledpattern[0]);
void nextPattern(void)
@@ -33,56 +41,75 @@ void nextPattern(void)
void HandleChainGame(void)
{
if ((button1.isPressed()) | (button3.isPressed()))
if (buttonIsPressed(ledpattern[patternIndex]))
{
if (!patternFlag)
{
//button detected, increase pattern
if (!firstpattern)
{
firstpattern = true;
}
else
{
nextPattern();
}
patternFlag = true;
}
turnOnLed(ledpattern[patternIndex]);
patternFlag = true;
}
if (button2.isPressed())
else if (!buttonIsPressed(ledpattern[patternIndex]))
{
if (!patternFlag)
if (patternFlag)
{
if (!firstpattern)
{
firstpattern = true;
nextPattern();
}
else
{
//second input, skip a pattern
nextPattern();
nextPattern();
}
patternFlag = true;
patternFlag = false;
nextPattern();
}
}
if (anybutton() && patternFlag)
{
//write pattern to the LEDs
digitalWrite(LED1, ledpattern[patternIndex][0]);
digitalWrite(LED2, ledpattern[patternIndex][1]);
digitalWrite(LED3, ledpattern[patternIndex][2]);
turnOffLed(ledpattern[patternIndex]);
}
else
{
//leds off
digitalWrite(LED1, 0);
digitalWrite(LED2, 0);
digitalWrite(LED3, 0);
patternFlag = false;
turnOffAllLed();
}
// 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;
// }
}