Skip to content

Laggy LEDs when doing multiple instructions #942

@MisterGoodDeal

Description

@MisterGoodDeal

Hello,
I'm using FastLED.h on my Arduino Leonardo Pro Micro and I've got an issue. When I'm using the default rainbow effect with no other instructions (just "Make a rainbow pls"), every thing is working smoothly, but when I'm writting other instructions in my code like controlling LEDs through serial port or coding"switch case"... ; the LEDs effect seems to be a bit laggy/LEDs goes red I think.
Here is the video showing my problem and here is the LEDs I've bought on Amazon
And here is my code if it can help :

String data;

// Gestion des LEDs
#include <FastLED.h>
#define DATA_PIN    9
//#define CLK_PIN   4
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    50
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          50
#define FRAMES_PER_SECOND  300

void setup() {
    delay(3000); // Delai 3 secondes
    Serial.begin(9600);
    Serial.setTimeout(50);

    // Initialisatation des LEDs
    FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
    FastLED.setBrightness(BRIGHTNESS);
}

uint8_t gHue = 0; // Variable de modification de la couleur pour les LEDs en mode rainbow
bool eclairage = true;
int type = 0;
int rapiditeRainbow = 50;

void loop() {
  gestionLEDs();
  gestionMain();
}

void gestionLEDs() {
  if(eclairage == true) {
    switch(type) {
      case 0:
        rainbow();
        break;
    }
  }
}

void gestionMain() {
    while(Serial.available()) {
      data = Serial.readString();// read the incoming data as string
      Serial.println(data);
    }
    if (data == "light=on")
      eclairage = true;
    else if (data == "light=off") {
      eclairage = false;
      eteindreLEDs();
    }
}

void rainbow() {
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
  FastLED.show(); // Afficher les mises à jour des LEDs
  FastLED.delay(1000/FRAMES_PER_SECOND); // Délai de mise à jour des LEDs
  EVERY_N_MILLISECONDS(rapiditeRainbow) { gHue++; } // Modification de la teinte des LEDs avec le mode rainbow
}

void eteindreLEDs() {
  for (int i = 0 ; i < NUM_LEDS ; ++i) {
    leds[i] = CRGB::Black;
  }
  FastLED.show();
}

Picture of my breadboard (don't pay attention to other things connected 😅):
camera_capture
And sorry if my english isn't good 😂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions