/*
erythro
Discord | Arduino | coding-help, 11:30AM Nov 18, 2023
Need help setting up this sequential light pattern
So I wanted to set up a simple light pattern, three LEDs turning
on in sequence.
I got the code for the sequential part done, but I want each of
the lights to pulse in and out before the next light.
I also got the code for the pulsating part off of google but it
is for a single light, can someone help?
*/
const int INTERVAL = 50; // sets speed
const int NUM_LEDS = 6;
const int LED_PINS[NUM_LEDS] = {11, 10, 9, 6, 5, 3};
unsigned long prevTime = 0;
int ledCounter = 0;
int ledIncrement = 10;
int ledBrightness = 0;
bool fadeLed(int ledNumber) {
bool isDone = false;
if (millis() - prevTime >= INTERVAL) {
prevTime = millis();
if (ledBrightness <= 0) ledIncrement = 10;
if (ledBrightness >= 250) ledIncrement = -10;
ledBrightness = ledBrightness + ledIncrement;
analogWrite(LED_PINS[ledNumber], ledBrightness);
Serial.print("LED #: ");
Serial.print(ledNumber);
Serial.print("\tValue: ");
Serial.println(ledBrightness);
if (ledBrightness <= 0) {
isDone = true;
}
}
return isDone;
}
void setup() {
Serial.begin(115200);
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(LED_PINS[i], OUTPUT);
}
}
void loop() {
bool isDone = fadeLed(ledCounter);
if (isDone) ledCounter++;
if (ledCounter >= NUM_LEDS) ledCounter = 0;
}