#include <Adafruit_NeoPixel.h>
#include <avdweb_Switch.h>
Adafruit_NeoPixel pixels(4, 0, NEO_GRB + NEO_KHZ800);

Switch buttonA = Switch(1);
Switch buttonB = Switch(2);

int start = millis();
int seconds = 0;

int digit = 0;
int timeDigit[4]= {0,0,0,0};

int color[10][3]{
                {0,0,0},
                {238,118,33},
                {255,0,0},
                {105,102,0},
                {255,255,0},
                {0,255,0},
                {0,0,255},
                {127,0,255},
                {100,120,120},
                {255,255,255}
                };

void timeNumber(int i, int j){
  pixels.setPixelColor(i,pixels.Color(color[j][0], color[j][1], color[j][2]));
}

void setup() {
  // put your setup code here, to run once:
  pixels.begin();
  pixels.clear();
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonA.poll();
  buttonB.poll();

  if(buttonA.pushed()){
    digit++;
    if(digit >= 4){
      digit = 0;
    }
    timeNumber(digit,9);
    pixels.show();
  }

  if(buttonA.released()){
    
    //color(digit, timeDigit[digit]);
    timeNumber(digit,timeDigit[digit]);
    pixels.show();

  }

  if(buttonB.pushed()){
    timeDigit[digit]++;
    timeNumber(digit,timeDigit[digit]);
  }

  if((millis() - start)>= 1000){
    start = millis();
    if(++seconds >= 60){
      seconds = 0;
      timeDigit[3]++;
      if(timeDigit[3]>=10){
        timeDigit[3] = 0;
        timeDigit[2]++;

        if(timeDigit[2]>=6){
          timeDigit[2] = 0;
          timeDigit[1]++;

          if(timeDigit[1]>=10){
            timeDigit[1] = 0;
            timeDigit[0]++;
          }

          if(timeDigit[1]>=4 && timeDigit[0]>=2){
            timeDigit[1] = 0;
            timeDigit[0] = 0;
          }
          
        }
      }
      for(int i =0; i<4; i++){
        timeNumber(i,timeDigit[i]);
      }
    }

  }
  pixels.show();
  
  delay(1);
  
}