Double capacitive sensor code

#include <Adafruit_NeoPixel.h>
#include <CapacitiveSensor.h>

#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, PIN, NEO_GRB + NEO_KHZ800);//pin doesnt need number because was already defined up top.
CapacitiveSensor cs_9_10 = CapacitiveSensor(9,10);
CapacitiveSensor cs_9_2 = CapacitiveSensor (9,2); //pin 9 which is sensor pin is shared.

void setup() {
cs_9_10.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 – just as an example
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to ‘off’

cs_9_10.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 – just as an example
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to ‘off’

}

void loop() {
long total1 = cs_9_10.capacitiveSensor(30);
long total2 = cs_9_2.capacitiveSensor (30);
Serial.println(total1);
Serial.println(total2);

if(total1 <= 50){
// before LED is on:
colorWipe(strip.Color(0, 0, 0), 0);
}
else {
// LED on:
// colorWipe(strip.Color(0,255,255), 0);
rainbowCycle (10);
}

if(total2 <= 50){
// turn LED on:
colorWipe(strip.Color(0, 0, 0), 0);
}
else {
//turn LED off:
colorWipe (strip.Color(255, 0, 100),0);
}
if(total2 <=300){
colorWipe(strip.Color(0,0,0),0);
} else {
colorWipe (strip.Color (20,100,200),0);
}

}

 

void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(10);
}
}

void rainbowCycle(uint8_t wait) {
uint16_t i, j;
//add timing interrupt here
for(j=0; j<256*1; j++) { // by changing number, changes how many 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(1 );
}
}

uint32_t Wheel(byte WheelPos) {
WheelPos = 255 – WheelPos;
if(WheelPos < 50) {
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);
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s