123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
#include <Adafruit_NeoPixel.h>
#include <CapacitiveSensor.h>
/*
* 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<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
delay(wait);
}
if(on == 1){
for(int i=0; i<strip.numPixels(); i++){
strip.setPixelColor(i, 0,0,0);
}
}
strip.show();
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) { // 1 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
void RGBLoop(){
for(int j = 0; j < 3; j++ ) {
// Fade IN
for(int k = 0; k < 256; 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);
}
// Fade OUT
for(int k = 255; k >= 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);
}