added multiple games [broken]
This commit is contained in:
133
src/main.cpp
133
src/main.cpp
@@ -1,91 +1,82 @@
|
||||
#include <Arduino.h>
|
||||
#include "buttons.h"
|
||||
#include "board.h"
|
||||
#include "chainGame.h"
|
||||
#include "detectled.h"
|
||||
#include "magicSwitchBoard.h"
|
||||
|
||||
#define LED1 PB14
|
||||
#define LED2 PB15
|
||||
#define LED3 PA8
|
||||
#define BUTTON1 PA0
|
||||
#define BUTTON2 PA1
|
||||
buttons button1(SWITCH12, 100, 1000, 1);
|
||||
buttons button2(SWITCH22, 100, 1000, 2);
|
||||
buttons button3(SWITCH32, 100, 1000, 3);
|
||||
buttons button4(SWITCH1, 100, 1000, 4);
|
||||
buttons button5(SWITCH2, 100, 1000, 5);
|
||||
buttons button6(SWITCH3, 100, 1000, 6);
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t patternIndex = 0;
|
||||
bool patternFlag = false;
|
||||
|
||||
|
||||
uint8_t ledpattern[5][3] = {
|
||||
{1,0,0},
|
||||
{0,0,1},
|
||||
{0,1,0},
|
||||
{0,1,0},
|
||||
{0,0,1}
|
||||
};
|
||||
|
||||
int patternlength = sizeof(ledpattern)/sizeof(ledpattern[0]);
|
||||
|
||||
void nextPattern( void )
|
||||
typedef enum
|
||||
{
|
||||
patternIndex++;
|
||||
if(patternIndex > patternlength)
|
||||
{
|
||||
patternIndex = 0;
|
||||
}
|
||||
}
|
||||
none,
|
||||
ChainGame,
|
||||
magicSwitchBoard,
|
||||
detectLED,
|
||||
last
|
||||
} game;
|
||||
|
||||
buttons button1(BUTTON1, 100,1000);
|
||||
buttons button2(BUTTON2, 100,1000);
|
||||
game currentGame = none;
|
||||
uint8_t gameState = 0;
|
||||
unsigned long gameTimeout = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED1, OUTPUT);
|
||||
pinMode(LED2, OUTPUT);
|
||||
pinMode(LED3, OUTPUT);
|
||||
|
||||
button1.begin();
|
||||
button2.begin();
|
||||
|
||||
initbuttons();
|
||||
|
||||
initDetectLed();
|
||||
|
||||
while (anybutton())
|
||||
{
|
||||
digitalWrite(LED1, 1);
|
||||
digitalWrite(LED2, 1);
|
||||
digitalWrite(LED3, 1);
|
||||
if (button4.raw())
|
||||
{
|
||||
currentGame = ChainGame;
|
||||
}
|
||||
if (button5.raw())
|
||||
{
|
||||
currentGame = magicSwitchBoard;
|
||||
}
|
||||
if (button6.raw())
|
||||
{
|
||||
currentGame = detectLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
void loop()
|
||||
{
|
||||
button1.update();
|
||||
button2.update();
|
||||
|
||||
if(button1.state())
|
||||
{
|
||||
if(!patternFlag)
|
||||
{
|
||||
//button detected, increase pattern
|
||||
nextPattern();
|
||||
patternFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(button2.state())
|
||||
{
|
||||
if(!patternFlag)
|
||||
{
|
||||
//second input, skip a pattern
|
||||
nextPattern();
|
||||
nextPattern();
|
||||
patternFlag = true;
|
||||
}
|
||||
}
|
||||
handleButtons();
|
||||
|
||||
if(button1.state() | button2.state() )
|
||||
switch (currentGame)
|
||||
{
|
||||
//write pattern to the LEDs
|
||||
digitalWrite(LED1,!ledpattern[patternIndex][0]);
|
||||
digitalWrite(LED2,!ledpattern[patternIndex][1]);
|
||||
digitalWrite(LED3,!ledpattern[patternIndex][2]);
|
||||
case magicSwitchBoard:
|
||||
{
|
||||
handleMagicSwitchBoard();
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case detectLED:
|
||||
{
|
||||
//leds off
|
||||
digitalWrite(LED1,1);
|
||||
digitalWrite(LED2,1);
|
||||
digitalWrite(LED3,1);
|
||||
patternFlag = false;
|
||||
handleDetectLed();
|
||||
}
|
||||
break;
|
||||
|
||||
case ChainGame:
|
||||
default:
|
||||
{
|
||||
HandleChainGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user