//-------------------------------------------------
//   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() {
  // Initialize serial.
  Serial.begin(9600); 
  
  // Initialize Circuit Playground library.
  CircuitPlayground.begin();
}

//----------------------------------------
void loop() {
  // Check if capacitive touch exceeds threshold.
  if (capButton(1)) {

      // Print message.
      Serial.println("Touched!");
      
      // But not too often.
      delay(debounce); 
  }
}

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