#include <mechButton.h>
#include "colorPixel.h"

#define NUM_SELECTIONS  4

mechButton  selectBtn(2);
mechButton  lockBtn(3);
colorPixel  pixles[NUM_SELECTIONS];
neoPixel    theStrip(NUM_SELECTIONS,4);
timeObj     drawTimer(100);
int         selection;

void setup() {
  
  Serial.begin(115200);
  Serial.println("Blue selects color, Green selects pixel.");
  theStrip.begin();
  theStrip.setAll(&black);
  theStrip.show();
  selection = 0;
  pixles[selection].stepColor();
  selectBtn.setCallback(selectClck);
  lockBtn.setCallback(lockClck);
}


void selectClck(void) {

  if (!selectBtn.getState()) {
    pixles[selection].stepColor();
  }
}


void lockClck(void) {

  if (!lockBtn.getState()) {
    Serial.println("lock pressed");
    pixles[selection].lockColor();
     Serial.println("lockColor() called");
    selection++;
    Serial.println("index bumped");
    if (selection<NUM_SELECTIONS) {
      Serial.println("index<NUM_SELECTIONS");
      pixles[selection].stepColor();
      Serial.println("stepColor() called");
    } else {
      Serial.print("Combo choice is : ");
      for(int i=0;i<NUM_SELECTIONS;i++) {
        Serial.print(pixles[i].getColorIndex());
        Serial.print("  ");
      }
      Serial.println();
    }
  }
  Serial.println("lockClck() exiting.");
}


void loop() {
  
  colorObj  aColor;
  
  idle();
  if (drawTimer.ding()) {
      for(int i=0;i<NUM_SELECTIONS;i++) {
        aColor = pixles[i].getColor();
        theStrip.setPixelColor(i,&aColor);
      }
    theStrip.show();
    drawTimer.start();
  }
}