#include "ArduinoTrace.h"
#include "ptScheduler.h"
#include "ezButton.h"
ptScheduler TasksSch=ptScheduler(1000000);
ezButton button0(2);
ezButton button1(3);
bool btn0Psd,btn1Psd;
bool a0,a1,a2;
bool b0,b1,b2;
int led1,led2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
button0.setDebounceTime(50);
button1.setDebounceTime(50);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(8, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
button0.loop();
button1.loop();
if(button0.isPressed()) btn0Psd=true;
if(button1.isPressed()) btn1Psd=true;
if(TasksSch.call())
{
buttonI0();
led(4);
led(6);
FunctionCalls();
}
}
void buttonI0()
{
enum {null,s1,s2,s3};
static int step=s1,pstep=null;
static int timer=0;
static bool entry=true;
static bool Q0=0,Q1=0,Q2=0;
//static bool R=0; //stored action
do
{
pstep=step;
switch(step)
{
case s1:
if(entry)
{
}
if(btn0Psd)
{
btn0Psd=false;
step=s2;
}
break;
case s2:
if(entry)
{
}
Q0=1;
if(btn0Psd)
{
btn0Psd=false;
Q0=0;
step=s3;
}
break;
case s3:
if(entry)
{
}
break;
}//end switch
if(step!=pstep)
{
entry=true;
}
else
{
entry=false;
}
}while(step!=pstep);
//DUMP(step);
//DUMP(pstep);
// display.setCursor(64,32);
// display.println(H);
if(timer>0) timer--;
//DUMP(G);
// if(G) prnMsg("Hola ");
// if(Y) prnMsg("como ");
// if(R) prnMsg("esta ");
a0=Q0;
//DUMP(a0);
}
void led(int pin)
{
enum {null,s4,s5,s6,s7,s8};
static int step=s4,pstep=null;
static int timer=0;
static bool entry=true;
static bool Q0=0,Q1=0,Q2=0;
//static bool R=0; //stored action
do
{
pstep=step;
switch(step)
{
case s4:
if(entry)
{
}
if(a0)
{
step=s5;
}
break;
case s5:
if(entry)
{
timer=1;
}
Q1=1;
if(timer==0)
{
Q1=0;
step=s6;
}
break;
case s6:
if(entry)
{
}
if(!a0)
{
//BREAK();
step=s7;
}
break;
case s7:
if(entry)
{
timer=1;
}
Q2=1;
if(timer==0)
{
Q2=0;
step=s8;
}
break;
case s8:
break;
}//end switch
if(step!=pstep)
{
entry=true;
}
else
{
entry=false;
}
}while(step!=pstep);
//DUMP(step);
//DUMP(pstep);
// display.setCursor(64,32);
// display.println(H);
if(timer>0) timer--;
//DUMP(G);
// if(G) prnMsg("Hola ");
// if(Y) prnMsg("como ");
// if(R) prnMsg("esta ");
//a0=G;a1=Y;a2=R;
b1=Q1;b2=Q2;
ledpin=pin;
DUMP(b1);
DUMP(b2);
}
void FunctionCalls()
{
if(b1)
{
digitalWrite(ledpin,HIGH);
DUMP("UNA SOLA ACTIVATION");
}
if(b2)
{
digitalWrite(ledpin,LOW);
DUMP("UNA SOLA DEACTIVATION");
}
//if(a0) prnMsg("Hola ");
//if(a1) prnMsg("como ");
// if(a2) prnMsg("esta? \n");
}
void prnMsg(String msg)
{
Serial.print(msg);
}