Hello! I'm trying to modify the example button code two switch between two LED modes on an LED strip by using a slide switch. When I try to switch modes, however, only one of them stays on. I'm thinking this may be a time element, thing, so if someone doesn't mind looking at my code I'd appreciate it! The wiring/materials I'm working with are identical to the ones found in this video: How to control LED Strips with Arduino - Cosplay Tutorial - YouTube
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
brighten();
darken();
} else {
colorWipe(strip.Color(255, 245, 0), 50);
}
}
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);
}
}
//Pulse
// 0 to 255
void brighten() {
uint16_t i, j;
for (j = 0; j < 255; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, j, 0);
}
strip.show();
delay(10);
}
delay(100);
}
// 255 to 0
void darken() {
Serial.begin(9600);
uint16_t i, j;
for (j = 255; j > 0; j--) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, j, 0);
}
strip.show();
delay(10);
Serial.println(j);
}
delay(100);
}
Wiring: