P@tch for GemmaM0
Arduino Code
#include <Adafruit_DotStar.h>
#include "Adafruit_FreeTouch.h"
#define CAPTOUCH_PIN 0 //capacitive touch pin
//The function: Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
//use internal data and clock definitions (INTERNAL_DS_DATA, INTERNAL_DS_CLK)
#define CAPTOUCH_PIN2 2
Adafruit_DotStar pixel = Adafruit_DotStar(1, INTERNAL_DS_DATA, INTERNAL_DS_CLK, DOTSTAR_BGR);
int touch = 650;
long oldState = 0;
int mode = 0; // Currently-active animation mode, 0-9
// set up capacitive touch button using the FreeTouch library
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(CAPTOUCH_PIN, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
void setup() {
Serial.begin(115200);
if (! qt_1.begin())
Serial.println("Failed to begin qt on pin A1");
pixel.begin();
}
void loop() {
Serial.print(qt_1.measure());
Serial.write(' ');
checkpress(); //check to see if the button's been pressed
delay(20);
}
void checkpress() {
// Get current button state D0.
long newState = qt_1.measure();
Serial.println(qt_1.measure());
if (newState > touch && oldState < touch) {
// Short delay to debounce button.
delay(500);
// Check if button is still low after debounce.
long newState = qt_1.measure(); }
if (newState > touch ) {
//pixel.setPixelColor(pixel number, R, G, B);
if(++mode > 3) mode = 0; // Advance to next mode, wrap around after #8
switch(mode) { // Start the new animation...
case 0:
pixel.clear(); pixel.show(); delay(500); //red brightness value 0-255
break;
case 1:
pixel.setPixelColor(0, 64, 0, 0); pixel.show(); delay(500); //red brightness value 0-255
break;
case 2:
pixel.setPixelColor(0, 0, 64, 0); pixel.show(); delay(500); //red brightness value 0-255
break;
}
}
// Set the last button state to the old state.
oldState = newState;
}