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

byte count=1;

const byte led0=2;
const byte led1=4;
const byte led2=6;
const byte led3=8;

enum {null,s1,s2};
bool entry=true;
int step=s1,pstep=null;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  pinMode(led0, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  displayCount();
  //incCount();
  //decCount();
  task1();
  delay(500);
}



void displayCount()
{
  digitalWrite(led0,bitRead(count,0));
  digitalWrite(led1,bitRead(count,1));
  digitalWrite(led2,bitRead(count,2));
  digitalWrite(led3,bitRead(count,3));
  DUMP(count);
}



void incCount()
{
  if(count<15)
  {
    count++;
  }
  else
  {
    count=0;
  }
}

void decCount()
{
  if(count>0)
  {
    count--;
  }
  else
  {
    count=15;
  }
}

void task1()
{
  pstep=step;
  switch(step)
  {
    case s1:
      if(entry)
      { 
        count=0;
        count++;
        step=s2;
      }
    break;
    case s2:
      if(count=15)
      {
        count--;
        step=s1;
      }
      else
      {
        entry=false;
      }
    break;
  }
  if(step!=pstep)
  {
    entry=true;
  }
  else
  {
    entry=false;
  }
}