HelloCapTouch2.ino
1 // SPDX-FileCopyrightText: 2020 Carter Nelson for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #include <Adafruit_CircuitPlayground.h> 6 7 #define CAP_THRESHOLD 50 8 #define DEBOUNCE 250 9 10 //////////////////////////////////////////////////////////////////////////// 11 boolean capButton(uint8_t pad) { 12 if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) { 13 return true; 14 } else { 15 return false; 16 } 17 } 18 19 //////////////////////////////////////////////////////////////////////////// 20 void setup() { 21 // Initialize serial. 22 Serial.begin(9600); 23 24 // Initialize Circuit Playground library. 25 CircuitPlayground.begin(); 26 } 27 28 //////////////////////////////////////////////////////////////////////////// 29 void loop() { 30 // Check if capacitive touch exceeds threshold. 31 if (capButton(1)) { 32 33 // Print message. 34 Serial.println("Touched!"); 35 36 // But not too often. 37 delay(DEBOUNCE); 38 } 39 }