#include <JC_Button.h>
#include <ArduinoTrace.h>
#define RLI 12
#define LB 11
#define LY 10
int b_y = 200;
int b_b = 400;
int millis_blue = 0;
int millis_yellow = 0;
bool state_b = false;
bool state_y = false;
Button BK_BTN(5);
Button BL_BTN(4);
Button YL_BTN(3);
static int step = 0;
bool BL_BK=false,YL_BK=false;
unsigned long currentMillis = millis();
unsigned long previousMillis = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(RLI, OUTPUT);
pinMode(LB, OUTPUT);
pinMode(LY, OUTPUT);
BK_BTN.begin();
BL_BTN.begin();
YL_BTN.begin();
}
void loop() {
// put your main code here, to run repeatedly:
currentMillis = millis();
BK_BTN.read();
BL_BTN.read();
YL_BTN.read();
startBlinkSeq();
handle_b();
handle_y();
DUMP(BL_BK);
//DUMP(YL_BK);
}
void startBlinkSeq() //start blinking
{
//static int step=0;
// static unsigned long previousMillis = currentMillis;
switch (step)
{
case 0:
if (BK_BTN.wasPressed())
{
digitalWrite(RLI, HIGH);
step=1;
}
break;
case 1:
if (BK_BTN.isReleased())
{
digitalWrite(RLI, LOW);
step=0;
}
else if(BL_BTN.wasPressed())
{
BL_BK=true;
step=2;
}
else if(YL_BTN.wasPressed())
{
YL_BK=true;
step=3;
}
break;
case 2:
step=4;
previousMillis=currentMillis;
break;
case 3:
step=4;
previousMillis=currentMillis;
break;
case 4:
if(currentMillis-previousMillis >= 3000)
{
digitalWrite(RLI, LOW);
step=0;
}
break;
}
}
void handle_b(){
if(BL_BK){
if(currentMillis - millis_blue >= 200){
millis_blue = currentMillis;
state_b = !state_b;
digitalWrite(LB,state_b);
}
}
}
void handle_y(){
if(YL_BK){
if(currentMillis - millis_yellow >= 200){
millis_yellow = currentMillis;
state_y = !state_y;
digitalWrite(LY,state_y);
}
}
}