#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 1
#define PIXEL_PIN 0 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 12 //change this number to whatever rgb you are using
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN);
// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
showType++;
if (showType > 14)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
break;
case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green
break;
case 3: colorWipe(strip.Color(0, 0, 255), 50); // Blue
break;
case 4: colorWipe(strip.Color(100, 0, 255), 50); // purp
break;
case 5: colorWipe(strip.Color(200, 0, 255), 50); // lite purp
break;
case 6: colorWipe(strip.Color(255, 0, 100), 50); // pink
break;
case 7: colorWipe(strip.Color(255, 255, 0), 50); // yellown
break;
case 8: colorWipe(strip.Color(255, 110, 20), 50); // orange
break;
case 9: colorWipe(strip.Color(255, 100, 100), 50); // Rorange
break;
case 10: colorWipe(strip.Color(255, 180, 40), 50); // lite orange
break;
case 11: colorWipe(strip.Color(0, 255, 255), 50); // LIGHT Blue
break;
case 12: colorWipe(strip.Color(0, 255, 100), 50); //greenish blue
break;
case 13: colorWipe(strip.Color(150, 255, 0), 50); //greenish red
break;
case 14: colorWipe(strip.Color(255, 255, 255), 50); // white
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);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 1, 0, WheelPos * 1);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 1, 255 - WheelPos * 1);
}
WheelPos -= 170;
return strip.Color(WheelPos * 1, 255 - WheelPos * 1, 0);
}
Comments