#include #include /* * CapitiveSense Library Demo Sketch * Oringinal sketch by Paul Badger 2008, Modified by PerfectPixel 2016 with code by Adafruit. * http://www.instructables.com/member/perfectpixel/ * Uses a high value resistor e.g. 10 megohm between send pin and receive pin * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values. * Receive pin is the sensor pin - try different amounts of foil/metal on this pin * Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet * *---LINKS--- * Original Sketch obtained from: * http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense * * Edited by PerfectPixel: * http://www.instructables.com/member/perfectpixel/ * * With code by Adafruit * http://www.adafruit.com/ */ #define PIN 9 //the pin the LED's are connected to. Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_RGB + NEO_KHZ800); CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4); // 1 megohm resistor between pins 4 & 2, pin 2 is sensor pin CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5); // 1 megohm resistor between pins 4 & 6, pin 6 is sensor pin CapacitiveSensor cs_2_8 = CapacitiveSensor(2,8); // 1 megohm resistor between pins 4 & 8, pin 8 is sensor pin int i = 0; int on = 1; void setup() { //Serial.begin(9600); pinMode(13, OUTPUT); strip.begin(); strip.show(); } void loop() { long start = millis(); long total1 = cs_2_4.capacitiveSensor(30); long total2 = cs_2_5.capacitiveSensor(30); long total3 = cs_2_8.capacitiveSensor(30); delay(10); if(total1 > 800){ i++; colorWipe(strip.Color(0,0,0),1); digitalWrite(13, HIGH); delay(100); digitalWrite(13, LOW); } else if(total3 > 800){ i--; colorWipe(strip.Color(0,0,0),1); digitalWrite(13, HIGH); delay(100); digitalWrite(13, LOW); } if(i > 9) i = 9; if(i < 0) i = 0; if(total2 < 800){ // Feel free to change these effects - they will be what is switch(i){ // displayed on each selecting using the capacitive touch buttons. case 0: colorWipe(strip.Color(255,255,255),5); break; case 1: colorWipe(strip.Color(255,100,0),5); break; case 2: colorWipe(strip.Color(140,0,227),5); break; case 3: colorWipe(strip.Color(255,0,0),5); break; case 4: colorWipe(strip.Color(237,7,176),5); break; case 5: colorWipe(strip.Color(0,255,0),5); break; case 6: FadeInOut(0x00, 0xFF, 0xB3); break; case 7: RGBLoop(); break; case 8: rainbowCycle(12); break; case 9: rainbow(12); break; // case 999; vixen() //activate vixen control - by pressing the middle button // break; //TODO - implement vixenlights control } } else { if(on == 0){ on = 1; //Serial.println("Vixen Control toggled ON"); delay(1000); i = 999; } else if(on == 1){ on = 0; //Serial.println("Vixen Control toggled OFF"); delay(1000); } } } void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i= 0; k--) { switch(j) { case 0: setAll(k,0,0); break; case 1: setAll(0,k,0); break; case 2: setAll(0,0,k); break; } strip.show(); delay(3); } } } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < 6; i++ ) { strip.setPixelColor(i, red, green, blue); } strip.show(); } void FadeInOut(byte red, byte green, byte blue){ float r, g, b; for(int k = 50; k < 255; k=k+3) { r = (k/256.0)*red; g = (k/256.0)*green; b = (k/256.0)*blue; setAll(r,g,b); strip.show(); delay(13); } delay(1500); for(int k = 255; k >= 50; k=k-3) { r = (k/256.0)*red; g = (k/256.0)*green; b = (k/256.0)*blue; setAll(r,g,b); strip.show(); delay(13); } delay(350); }