#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Digital IO pin connected to the button. This will be driven with a
// pull-up resistor so the switch pulls the pin to ground momentarily.
// On a high -> low transition the button press logic will execute.
#define BUTTON_PIN 2
#define BUTTON_PIN2 3
#define BUTTON_PIN3 4
#define BUTTON_PIN4 5
#define BUTTON_PIN5 6
#define PIXEL_PIN1 8 // Digital IO pin connected to the NeoPixels.
#define PIXEL_PIN2 9
#define PIXEL_PIN3 10
#define PIXEL_PIN4 11
#define PIXEL_PIN5 12 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 1 // Number of NeoPixels
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2(PIXEL_COUNT, PIXEL_PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3(PIXEL_COUNT, PIXEL_PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip4(PIXEL_COUNT, PIXEL_PIN4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip5(PIXEL_COUNT, PIXEL_PIN5, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
boolean oldState = HIGH;
boolean oldState2 = HIGH;
boolean oldState3 = HIGH;
boolean oldState4 = HIGH;
boolean oldState5 = HIGH;
int mode = 0; // Currently-active animation mode, 0-9
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(BUTTON_PIN2, INPUT_PULLUP);
pinMode(BUTTON_PIN3, INPUT_PULLUP);
pinMode(BUTTON_PIN4, INPUT_PULLUP);
pinMode(BUTTON_PIN5, INPUT_PULLUP);
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip.show(); // Initialize all pixels to 'off'
strip2.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip2.show(); // Initialize all pixels to 'off'
strip3.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip3.show(); // Initialize all pixels to 'off'
strip4.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip4.show(); // Initialize all pixels to 'off'
strip5.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip5.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
boolean newState = digitalRead(BUTTON_PIN);
boolean newState2 = digitalRead(BUTTON_PIN2);
boolean newState3 = digitalRead(BUTTON_PIN3);
boolean newState4 = digitalRead(BUTTON_PIN4);
boolean newState5 = digitalRead(BUTTON_PIN5);
// Check if state changed from high to low (button press).
if ((newState == LOW) && (oldState == HIGH)) {
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) { // Yes, still low
if (++mode > 10) mode = 0; // Advance to next mode, wrap around after #8
switch (mode) { // Start the new animation...
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(255, 255, 255), 50); // White
break;
case 5:
colorWipe(strip.Color(255, 255, 0), 50); // Yellow
break;
case 6:
colorWipe(strip.Color(255, 25, 125), 50); // Hot Pink
break;
case 7:
colorWipe(strip.Color(255, 150, 50), 50); // Warm White
break;
case 8:
colorWipe(strip.Color(255, 65, 255), 50); // Purple
break;
case 9:
colorWipe(strip.Color(50, 200, 255), 50); // Light Blue
break;
case 10:
rainbow(10);
break;
}
}
}
// Check if state changed from high to low (button press).
if ((newState2 == LOW) && (oldState2 == HIGH)) {
delay(20);
// Check if button is still low after debounce.
newState2 = digitalRead(BUTTON_PIN2);
if (newState2 == LOW) { // Yes, still low
if (++mode > 10) mode = 0; // Advance to next mode, wrap around after #8
switch (mode) { // Start the new animation...
case 0:
colorWipe2(strip2.Color(0, 0, 0), 50); // Black/off
break;
case 1:
colorWipe2(strip2.Color(255, 0, 0), 50); // Red
break;
case 2:
colorWipe2(strip2.Color(0, 255, 0), 50); // Green
break;
case 3:
colorWipe2(strip2.Color(0, 0, 255), 50); // Blue
break;
case 4:
colorWipe2(strip2.Color(255, 255, 255), 50); // White
break;
case 5:
colorWipe2(strip2.Color(255, 255, 0), 50); // Yellow
break;
case 6:
colorWipe2(strip2.Color(255, 25, 125), 50); // Hot Pink
break;
case 7:
colorWipe2(strip2.Color(255, 150, 50), 50); // Warm White
break;
case 8:
colorWipe2(strip2.Color(255, 65, 255), 50); // Purple
break;
case 9:
colorWipe2(strip2.Color(50, 200, 255), 50); // Light Blue
break;
case 10:
rainbow2(10);
break;
}
}
}
// Check if state changed from high to low (button press).
if ((newState3 == LOW) && (oldState3 == HIGH)) {
delay(20);
// Check if button is still low after debounce.
newState3 = digitalRead(BUTTON_PIN3);
if (newState3 == LOW) { // Yes, still low
if (++mode > 10) mode = 0; // Advance to next mode, wrap around after #8
switch (mode) { // Start the new animation...
case 0:
colorWipe3(strip3.Color(0, 0, 0), 50); // Black/off
break;
case 1:
colorWipe3(strip3.Color(255, 0, 0), 50); // Red
break;
case 2:
colorWipe3(strip3.Color(0, 255, 0), 50); // Green
break;
case 3:
colorWipe3(strip3.Color(0, 0, 255), 50); // Blue
break;
case 4:
colorWipe3(strip3.Color(255, 255, 255), 50); // White
break;
case 5:
colorWipe3(strip3.Color(255, 255, 0), 50); // Yellow
break;
case 6:
colorWipe3(strip3.Color(255, 25, 125), 50); // Hot Pink
break;
case 7:
colorWipe3(strip3.Color(255, 150, 50), 50); // Warm White
break;
case 8:
colorWipe3(strip3.Color(255, 65, 255), 50); // Purple
break;
case 9:
colorWipe3(strip3.Color(50, 200, 255), 50); // Light Blue
break;
case 10:
rainbow3(10);
break;
}
}
}
// Check if state changed from high to low (button press).
if ((newState4 == LOW) && (oldState4 == HIGH)) {
delay(20);
// Check if button is still low after debounce.
newState4 = digitalRead(BUTTON_PIN4);
if (newState4 == LOW) { // Yes, still low
if (++mode > 10) mode = 0; // Advance to next mode, wrap around after #8
switch (mode) { // Start the new animation...
case 0:
colorWipe4(strip4.Color(0, 0, 0), 50); // Black/off
break;
case 1:
colorWipe4(strip4.Color(255, 0, 0), 50); // Red
break;
case 2:
colorWipe4(strip4.Color(0, 255, 0), 50); // Green
break;
case 3:
colorWipe4(strip4.Color(0, 0, 255), 50); // Blue
break;
case 4:
colorWipe4(strip4.Color(255, 255, 255), 50); // White
break;
case 5:
colorWipe4(strip4.Color(255, 255, 0), 50); // Yellow
break;
case 6:
colorWipe4(strip4.Color(255, 25, 125), 50); // Hot Pink
break;
case 7:
colorWipe4(strip4.Color(255, 150, 50), 50); // Warm White
break;
case 8:
colorWipe4(strip4.Color(255, 65, 255), 50); // Purple
break;
case 9:
colorWipe4(strip4.Color(50, 200, 255), 50); // Light Blue
break;
case 10:
rainbow4(10);
break;
}
}
}
// Check if state changed from high to low (button press).
if ((newState5 == LOW) && (oldState5 == HIGH)) {
delay(20);
// Check if button is still low after debounce.
newState5 = digitalRead(BUTTON_PIN5);
if (newState5 == LOW) { // Yes, still low
if (++mode > 10) mode = 0; // Advance to next mode, wrap around after #8
switch (mode) { // Start the new animation...
case 0:
colorWipe5(strip5.Color(0, 0, 0), 50); // Black/off
break;
case 1:
colorWipe5(strip5.Color(255, 0, 0), 50); // Red
break;
case 2:
colorWipe5(strip5.Color(0, 255, 0), 50); // Green
break;
case 3:
colorWipe5(strip5.Color(0, 0, 255), 50); // Blue
break;
case 4:
colorWipe5(strip5.Color(255, 255, 255), 50); // White
break;
case 5:
colorWipe5(strip5.Color(255, 255, 0), 50); // Yellow
break;
case 6:
colorWipe5(strip5.Color(255, 25, 125), 50); // Hot Pink
break;
case 7:
colorWipe5(strip5.Color(255, 150, 50), 50); // Warm White
break;
case 8:
colorWipe5(strip5.Color(255, 65, 255), 50); // Purple
break;
case 9:
colorWipe5(strip5.Color(50, 200, 255), 50); // Light Blue
break;
case 10:
rainbow5(10);
break;
}
}
}
// Set the last-read button state to the old state.
oldState = newState;
oldState2 = newState2;
oldState3 = newState3;
oldState4 = newState4;
oldState5 = newState5;
}
void colorWipe(uint32_t color, int wait) {
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void colorWipe2(uint32_t color, int wait) {
for (int i = 0; i < strip2.numPixels(); i++) { // For each pixel in strip...
strip2.setPixelColor(i, color); // Set pixel's color (in RAM)
strip2.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void colorWipe3(uint32_t color, int wait) {
for (int i = 0; i < strip3.numPixels(); i++) { // For each pixel in strip...
strip3.setPixelColor(i, color); // Set pixel's color (in RAM)
strip3.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void colorWipe4(uint32_t color, int wait) {
for (int i = 0; i < strip4.numPixels(); i++) { // For each pixel in strip...
strip4.setPixelColor(i, color); // Set pixel's color (in RAM)
strip4.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void colorWipe5(uint32_t color, int wait) {
for (int i = 0; i < strip5.numPixels(); i++) { // For each pixel in strip...
strip5.setPixelColor(i, color); // Set pixel's color (in RAM)
strip5.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
for (long firstPixelHue = 0; firstPixelHue < 3 * 65536; firstPixelHue += 256) {
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
void rainbow2(int wait) {
for (long firstPixelHue = 0; firstPixelHue < 3 * 65536; firstPixelHue += 256) {
for (int i = 0; i < strip2.numPixels(); i++) { // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip2.numPixels());
strip2.setPixelColor(i, strip2.gamma32(strip2.ColorHSV(pixelHue)));
}
strip2.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
void rainbow3(int wait) {
for (long firstPixelHue = 0; firstPixelHue < 3 * 65536; firstPixelHue += 256) {
for (int i = 0; i < strip3.numPixels(); i++) { // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip3.numPixels());
strip3.setPixelColor(i, strip3.gamma32(strip3.ColorHSV(pixelHue)));
}
strip3.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
void rainbow4(int wait) {
for (long firstPixelHue = 0; firstPixelHue < 3 * 65536; firstPixelHue += 256) {
for (int i = 0; i < strip4.numPixels(); i++) { // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip4.numPixels());
strip4.setPixelColor(i, strip4.gamma32(strip4.ColorHSV(pixelHue)));
}
strip4.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
void rainbow5(int wait) {
for (long firstPixelHue = 0; firstPixelHue < 3 * 65536; firstPixelHue += 256) {
for (int i = 0; i < strip5.numPixels(); i++) { // For each pixel in strip...
int pixelHue = firstPixelHue + (i * 65536L / strip5.numPixels());
strip5.setPixelColor(i, strip5.gamma32(strip5.ColorHSV(pixelHue)));
}
strip5.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}