#include <Adafruit_NeoPixel.h>
#define Button 2
#define Count 24
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Count, 1, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
int X = 50; //colorwipe speed
int Y = 20; // Rainbow speed
int PotVal;
int PotOut;
void setup() {
pinMode(Button,INPUT);
pinMode(0,OUTPUT);
strip.begin();
strip.show();
}
void loop() {
bool newState = digitalRead(Button);
if (newState == LOW && oldState == HIGH) {
delay(20);
newState = digitalRead(Button);
if (newState == LOW) {
showType++;
if (showType > 9)
showType=0;
startShow(showType);
PotVal = analogRead(3);
PotOut = map (PotVal, 0, 1023, 0, 255);
strip.setBrightness(PotOut);
}
}
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), X); // Black/off
break;
case 1: colorWipe(strip.Color(255, 0, 0), X); // Red
break;
case 2: colorWipe(strip.Color(0, 255, 0), X); // Green
break;
case 3: colorWipe(strip.Color(0, 0, 255), X); // Blue
break;
case 4: colorWipe(strip.Color(255, 0, 255), X); // Blue
break;
case 5: colorWipe(strip.Color(0, 255, 255), X); // Blue
break;
case 6: colorWipe(strip.Color(255, 255, 0), X); // Blue
break;
case 7: rainbow(Y);
break;
case 8: rainbowCycle(Y);
break;
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
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);
PotVal = analogRead(3);
PotOut = map (PotVal, 0, 1023, 0, 255);
strip.setBrightness(PotOut);
}
}
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) { // 5 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);
PotVal = analogRead(3);
PotOut = map (PotVal, 0, 1023, 0, 255);
strip.setBrightness(PotOut);
}
}
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);
}