How to Synchronize Two LED Strip Effects to Start Simultaneously?
Hello everyone, I need help ASAP 😩 I have two LED strips that I want to light up simultaneously (one gradually from 0% to 20% brightness; the other with a chasing light effect). My two functions work well independently or one after the other, but it's impossible to get them to start simultaneously. Does anyone have any ideas?
I'm using an Arduino Uno board for this project.
Thanks!
Code: 👩💻
Solution:Jump to solution
Your code contains certain errors like
Repetition in the loop function, you misplaced the function fastLed.show(), you didn't multi thread the led handling....
6 Replies
#include <FastLED.h>
#define NUM_LEDS_BAND1 132
#define NUM_LEDS_BAND2 96
#define DATA_PIN_BAND1 2
#define DATA_PIN_BAND2 3
CRGB leds_band1[NUM_LEDS_BAND1];
CRGB leds_band2[NUM_LEDS_BAND2];
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN_BAND1, RGB>(leds_band1, NUM_LEDS_BAND1);
FastLED.addLeds<WS2812B, DATA_PIN_BAND2, RGB>(leds_band2, NUM_LEDS_BAND2);
}
void loop() {
idle(leds_band1, NUM_LEDS_BAND1, leds_band2, NUM_LEDS_BAND2);
chenillard(leds_band1, NUM_LEDS_BAND1, leds_band2, NUM_LEDS_BAND2);
}
void idle(CRGB leds1[], int numLEDs1, CRGB leds2[], int numLEDs2) {
for (int brightness = 0; brightness <= 51; brightness++) {
FastLED.setBrightness(brightness);
for (int i = 0; i < 59; i++) {
leds1[i] = CRGB(46, 51, 36);
}
FastLED.show(); // a mettre dans la dernière boucle for
delay(1); // a mettre dans la dernière boucle for
}
while (true) {
}
}
void chenillard(CRGB leds1[], int numLEDs1, CRGB leds2[], int numLEDs2) {
for (int i=0; i<=29; i++){
leds2[i] = CRGB(0, 51, 36);
FastLED.show();
delay(15);
} }
} }
@Camila_99$$ No worries , The key to running functions simultaneously on Arduino is by using interrupts or loop structures
Solution
Your code contains certain errors like
Repetition in the loop function, you misplaced the function fastLed.show(), you didn't multi thread the led handling.
Morning @Dtynin Thanks for the tip! I'll look into using interrupts or modifying my loop structure to achieve this . 🤓
Morning @Enthernet Code Hum OK Thanks for pointing out the issues. I'll work on addressing the repetition in the loop function .
I will reposition the
FastLED.show()
call too. 🤝#include <FastLED.h>
#define NUM_LEDS_BAND1 132
#define NUM_LEDS_BAND2 96
#define DATA_PIN_BAND1 2
#define DATA_PIN_BAND2 3
CRGB leds_band1[NUM_LEDS_BAND1];
CRGB leds_band2[NUM_LEDS_BAND2];
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN_BAND1, RGB>(leds_band1, NUM_LEDS_BAND1);
FastLED.addLeds<WS2812B, DATA_PIN_BAND2, RGB>(leds_band2, NUM_LEDS_BAND2);
}
void loop() {
static uint8_t brightness = 0;
static uint8_t chaseIndex = 0;
idle(leds_band1, NUM_LEDS_BAND1, brightness);
chenillard(leds_band2, NUM_LEDS_BAND2, chaseIndex);
FastLED.show();
delay(15);
brightness = (brightness < 51) ? brightness + 1 : 51;
chaseIndex = (chaseIndex < NUM_LEDS_BAND2) ? chaseIndex + 1 : 0;
}
void idle(CRGB leds1[], int numLEDs1, uint8_t brightness) {
FastLED.setBrightness(brightness);
for (int i = 0; i < numLEDs1; i++) {
leds1[i] = CRGB(46, 51, 36);
}
}
void chenillard(CRGB leds2[], int numLEDs2, uint8_t chaseIndex) {
for (int i = 0; i < numLEDs2; i++) {
if (i == chaseIndex) {
leds2[i] = CRGB(0, 51, 36);
} else {
leds2[i] = CRGB::Black;
}
}
}