#include <timeObj.h>
#include <mechButton.h>

#define NUM_TIMES  10

float       times[NUM_TIMES];
timeObj     timer(0,false); 
int         LEDs[] = {2,3,4,5,6,7,8,9,10,11};
int         timeIndex;
mechButton  startButton(12);

void setup() {
  
  for (int i=0;i<NUM_TIMES;i++) {
    pinMode(LEDs[i],OUTPUT);
  }
  times[0] = 100;
  times[1] = 200;
  times[2] = 300;
  times[3] = 400;
  times[4] = 500;
  times[5] = 400;
  times[6] = 300;
  times[7] = 200;
  times[8] = 100;
  times[9] = 500;
  startButton.setCallback(btnClk);
}

void LEDsOff(void) {
  
  for (int i=0;i<NUM_TIMES;i++) {
    digitalWrite(LEDs[i],LOW);
  }
}


void btnClk(void) {

  if (!startButton.getState()) {
    LEDsOff();
    timeIndex = 0;
    digitalWrite(LEDs[timeIndex],HIGH);
    timer.setTime(times[timeIndex]);
  }
}


void loop() {

  idle();
  if (timer.ding()) {
    digitalWrite(LEDs[timeIndex],LOW);
    timeIndex++;
    if (timeIndex<NUM_TIMES) {
      digitalWrite(LEDs[timeIndex],HIGH);
      timer.setTime(times[timeIndex]);
    } else {
      timer.reset();
    }
  }
}