#include <Adafruit_NeoPixel.h>
#include <MsTimer2.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define TouchSensor 9 // Pin for capactitive touch sensor
boolean currentState = LOW;
boolean lastState = LOW;
int event = 0;
int eventCount = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
pinMode(TouchSensor, INPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
MsTimer2::set(60, backGroundRun);
MsTimer2::start();
}
void loop() {
currentState = digitalRead(TouchSensor);
if (currentState == LOW && lastState == HIGH){
eventCount++;
event = eventCount % 3;
}
lastState = currentState;
}
void backGroundRun()
{
if(event == 0)
{
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0));
}
strip.show();
}else if(event == 1)
{
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(0, 255, 0));
}
strip.show();
}
else
{
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
}
}