modified games
This commit is contained in:
144
src/main.cpp
144
src/main.cpp
@@ -1,22 +1,21 @@
|
||||
#include <Arduino.h>
|
||||
//#include "buttons.h"
|
||||
#include "board.h"
|
||||
#include "chainGame.h"
|
||||
#include "detectled.h"
|
||||
#include "magicSwitchBoard.h"
|
||||
#include "simpleled.h"
|
||||
#include "buttons.h"
|
||||
//#include "JC_Button.h"
|
||||
#include "led.h"
|
||||
|
||||
|
||||
extern c_button button1;
|
||||
extern c_button button2;
|
||||
extern c_button button3;
|
||||
#define TIMEOUT 15000 // 15sec * 1000ms
|
||||
#define GAMESELECTTIMEOUT 7000 // 7sec * 1000ms
|
||||
|
||||
typedef enum
|
||||
{
|
||||
none,
|
||||
sleep,
|
||||
idle,
|
||||
SimpleLed,
|
||||
ChainGame,
|
||||
magicSwitchBoard,
|
||||
detectLED,
|
||||
@@ -24,34 +23,114 @@ typedef enum
|
||||
} game;
|
||||
|
||||
game currentGame = none;
|
||||
game nextGame = none;
|
||||
uint8_t gameState = 0;
|
||||
uint64_t lasttimeOut = 0;
|
||||
uint64_t GameSelectTimer = 0;
|
||||
|
||||
void HandleIdle(void)
|
||||
{
|
||||
//green button first released
|
||||
if (buttonIsPressed(YELLOW) && !buttonIsPressed(RED) && buttonIsPressed(GREEN) && (nextGame == none))
|
||||
{
|
||||
//prepare for next game
|
||||
nextGame = ChainGame;
|
||||
}
|
||||
|
||||
//yellow button first released
|
||||
if (buttonIsPressed(YELLOW) && buttonIsPressed(RED) && !buttonIsPressed(GREEN) & (nextGame == none))
|
||||
{
|
||||
//prepare for next game
|
||||
nextGame = magicSwitchBoard;
|
||||
}
|
||||
|
||||
//wait for all buttons to be switched off
|
||||
if (!anybutton())
|
||||
{
|
||||
currentGame = nextGame;
|
||||
nextGame = none;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleGameSelectTimeout(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if(buttonIsPressed(YELLOW) && buttonIsPressed(RED) && buttonIsPressed(GREEN))
|
||||
//if (yellow && red && green)
|
||||
{
|
||||
//all buttons pressed, wait for next game
|
||||
if (!GameSelectTimer)
|
||||
{
|
||||
GameSelectTimer = currentmillis;
|
||||
}
|
||||
else
|
||||
{
|
||||
//check timeout
|
||||
if (currentmillis - GameSelectTimer > GAMESELECTTIMEOUT)
|
||||
{
|
||||
currentGame = idle;
|
||||
GameSelectTimer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//no gameselect sequence initiated
|
||||
GameSelectTimer = currentmillis;
|
||||
}
|
||||
}
|
||||
|
||||
// void HandleTimeOut(void)
|
||||
// {
|
||||
// uint64_t currentmillis = millis();
|
||||
// if (!lasttimeOut)
|
||||
// {
|
||||
// lasttimeOut = currentmillis;
|
||||
// }
|
||||
|
||||
// //check if lastTime is initialized or timeout expired
|
||||
// if ((currentmillis - lasttimeOut > TIMEOUT))
|
||||
// {
|
||||
// //handle timeout
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (anybutton())
|
||||
// {
|
||||
// //game in progress, update timer
|
||||
// lasttimeOut = currentmillis;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED1, OUTPUT);
|
||||
pinMode(LED2, OUTPUT);
|
||||
pinMode(LED3, OUTPUT);
|
||||
pinMode(SYS_WKUP3, INPUT);
|
||||
|
||||
c_leds *ledlist = getledlist();
|
||||
|
||||
ledlist->AddLed(LED1, DETECT1, 1, 844, YELLOW, false);
|
||||
ledlist->AddLed(LED2, DETECT2, 2, 512, RED, false);
|
||||
ledlist->AddLed(LED3, DETECT3, 2, 92, GREEN, false);
|
||||
|
||||
ledlist->begin();
|
||||
|
||||
initLeds();
|
||||
initButtons();
|
||||
initDetectLed();
|
||||
initSimpleLed();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
handleButtons();
|
||||
//handleSystemTimeout();
|
||||
//HandleTimeOut();
|
||||
HandleGameSelectTimeout();
|
||||
|
||||
switch (currentGame)
|
||||
{
|
||||
case idle:
|
||||
{
|
||||
HandleIdle();
|
||||
}
|
||||
break;
|
||||
|
||||
case SimpleLed:
|
||||
{
|
||||
handleSimpleLed();
|
||||
}
|
||||
break;
|
||||
|
||||
case magicSwitchBoard:
|
||||
{
|
||||
handleMagicSwitchBoard();
|
||||
@@ -73,30 +152,29 @@ void loop()
|
||||
|
||||
case none:
|
||||
{
|
||||
currentGame = ChainGame;
|
||||
digitalWrite(LED1, 0);
|
||||
digitalWrite(LED2, 0);
|
||||
digitalWrite(LED3, 0);
|
||||
if (button1.isPressed())
|
||||
currentGame = SimpleLed;
|
||||
if (buttonIsPressed(YELLOW))
|
||||
{
|
||||
digitalWrite(LED1, 1);
|
||||
currentGame = ChainGame;
|
||||
turnOnLed(YELLOW);
|
||||
}
|
||||
if (button2.isPressed())
|
||||
if (buttonIsPressed(RED))
|
||||
{
|
||||
currentGame = magicSwitchBoard;
|
||||
digitalWrite(LED2, 1);
|
||||
turnOnLed(RED);
|
||||
}
|
||||
|
||||
if (button3.isPressed())
|
||||
if (buttonIsPressed(GREEN))
|
||||
{
|
||||
digitalWrite(LED3, 1);
|
||||
currentGame = detectLED;
|
||||
turnOnLed(GREEN);
|
||||
}
|
||||
|
||||
while (anybutton());
|
||||
while (anybutton())
|
||||
;
|
||||
|
||||
turnOffAllLed();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user