I am trying to break out of a 5 LED fading loop using a push button.
When the button is pressed I want the Fading LEDS to go to 255 and stay there
When the button is pressed again i want the LEDS to go back to the fading loop.
I'm not quit sure how to add a switch case statement into my sketch of even if that's the best was to achieve what I'm trying to accomplish
any and all hep will be greatly appreciated. Thank you all
#include <Curve.h>
#include <LEDFader.h>
#/*
Fades 5 LEDs, all to random PWM values and durations.
This uses all the PWM pins on the UNO board.
Circuit
-------
* Connect the anode (flat side/long leg) of each LED to one of the PWM pins listed below on the arduino, via a 220 ohm resistor.
* Connect the cathode (short leg) of each LED to ground.
* PWM Pins on the UNO board:
- 3
- 5
- 6
- 9
- 10
- 11
RGB LEDs
--------
You can also use this code with 2 RGB LEDs. This will fade each of the colors on an off at
random durations and intensities. Check the LED datasheet to see if it's a common cathode or anode and
which legs are which.
For common anode RGB LEDs, attach the anode to ground and each cathode leg to a PWM pin through a
resistor.
For common cathode RGB LEDs, the cathode will be connected straight to 5+ and each
of the anode legs will be connected to a PWM pin through a resistor. Since you're basically attaching
the ground pins to the arduino, the brightness values are reversed: 0 is 100% and 255 is completely off.
This is called current sinking.
*/
#define LED_NUM 5
// 5 LEDs
LEDFader leds[LED_NUM] = {
LEDFader(3),
LEDFader(5),
LEDFader(6),
LEDFader(9),
LEDFader(10),
};
void setup() {
}
void loop() {
// Update all LEDs and start new fades if any are done
for (byte i = 0; i < LED_NUM; i++) {
LEDFader *led = &leds[i];
led->update();
// Set new fade
if (led->is_fading() == false) {
int duration = random(1000, 3000); // between 1 - 3 seconds
// Up
if (led->get_value() == 0) {
byte color = random(100, 255);
led->fade(color, duration);
}
// Down
else {
led->fade(0, duration);
}
}
}
}