//-------------------------------------------------
//   Demonstrating the capacitive touch sensors on 
//   the Circuit Playground:
//
//   (Using the pad labelled: "TX #1")
//------------------------------------------------- 

#include <Adafruit_CircuitPlayground.h>

int cap_threshold = 30;
int debounce = 150;

void setup() {
  CircuitPlayground.begin();
  Serial.begin(9600); 
}

void loop() {  
  // Check if capacitive touch exceeds threshold.
  if (capButton(1)) {
//   (Arguments are: Pixel #, R, G, B)
  CircuitPlayground.setPixelColor(0, 255,   0,   0);
  CircuitPlayground.setPixelColor(1, 128, 128,   0);
  CircuitPlayground.setPixelColor(2,   0, 255,   0);
  CircuitPlayground.setPixelColor(3,   0, 128, 128);
  CircuitPlayground.setPixelColor(4,   0,   0, 255);
  CircuitPlayground.setPixelColor(5, 255,   0,   0);
  CircuitPlayground.setPixelColor(6, 128, 128,   0);
  CircuitPlayground.setPixelColor(7,   0, 255,   0);
  CircuitPlayground.setPixelColor(8,   0, 128, 128);
  CircuitPlayground.setPixelColor(9,   0,   0, 255);
  delay(200);
    CircuitPlayground.clearPixels();
  delay(200);
} else {
  for(int i = 0; i < 10; i++){ 
      CircuitPlayground.setPixelColor(i, 0, 128, 128);
      Serial.println(CircuitPlayground.readCap(1));
  }
  }
}

//----------------------------------------
boolean capButton(uint8_t pad) {
  if (CircuitPlayground.readCap(pad) > cap_threshold) {
    return true;  
  } else {
    return false;
  }
}
