#include "ArduinoTrace.h"
#include "ptScheduler.h"
#include "ezButton.h"

ezButton button(7);
bool flag;

ptScheduler Task1Sch=ptScheduler(1000000);
bool T1flag;
bool ledState=LOW;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  button.setDebounceTime(50);
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  button.loop();
  if(button.isPressed())
  {
     flag=true;
  }
  
  if(Task1Sch.call()) Task1();

}
void Task1()
{
  enum {s0,s1,s2};
  static int timer1,timer2;
  int static step=s0;
  int pstep=s0;

  do
  {
    pstep=step;
    
    switch(step)
    {
      case s0:    
        if(flag)
        {
          flag=false;
          timer1=1;
          step=s1;
        }

      break;

      case s1:
        digitalWrite(13,HIGH);
        if(timer1==0)
        {
          digitalWrite(13,LOW);
          timer2=2;
          step=s2;
        }
      break;
      case s2:
        if(timer2==0)
        {
          timer1=1;
          step=s1;
        }
      break;
   }
   if((pstep==s2||pstep==s1) && step==s1) DUMP(millis()); //verificar cada cuanto ON
   if(pstep==s1 && step==s2) DUMP(millis()); //verificar cada cuanto OFF
  }while(step!=pstep);
  if(timer1>0) timer1--;
  if(timer2>0) timer2--;
}