Hello! Little bit new to programming here.
At the moment I have a program that runs an LED strip through various lighting effects, but I want to be
able to interrupt those effects at any time and then switch to a solid color but at 50% brightness.
The button code was taken from the Neopixel Buttoncycler example and so have most of the effects.
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255)
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(REDBULB_PIN, OUTPUT);
}
// loop() function -- runs repeatedly as long as board is on ---------------
void loop() {
int strobe = 0;
boolean 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) { // Yes, still low
if(++mode > 8) mode = 0; // Advance to next mode, wrap around after #8
switch(mode) {
case 0:
OFF();
break;
case 1:
colorWipe(strip.Color( 0, 255, 0), 50);
brighten();
darken();
brighten();
darken();
brighten();
darken();
for (strobe = 0; strobe <10; strobe++) {
ON(strip.Color(0,255,0));
delay(100);
OFF();
}
break;
case 2:
strip.setBrightness(55);
colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
}
}
}
oldState = newState;
}
Please let me know if I am in the wrong place, or if I am doing something wrong. Thanks!