so I am running a program on arduino with Fast.Led library to create a radar with leds (WS2811) I have been able to achieve the led pattern correctly, however, i can't seem to make the speed of the pattern increase depending on time increasing.
This is the code i have so far, any input will HIGHLY help as i am a newbie here hihi Thank You!
#include <FastLED.h>
#define LED_DT 3
#define COLOR_ORDER BRG
#define LED_TYPE WS2811
#define NUM_LEDS 15
uint8_t max_bright = 55;
struct CRGB leds[NUM_LEDS];
void setLEDs(int K, int N) {
FastLED.clear();
for (int i = 0; i < NUM_LEDS; i++) {
if (i % N == K) leds[i] = CRGB(200,0,0); // set red LED
}
FastLED.show();
}
void setup() {
Serial.begin(57600);
delay(1000);
FastLED.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(max_bright);
}
void loop() {
int N = 5;
unsigned long startTime = millis();
int initialDelay = 50;
int currentDelay = initialDelay;
for (int i = 0; i < N; i++) {
setLEDs(i, N);
delay(currentDelay);
}
// Increase delay every second
while (millis() - startTime < 1000) {
currentDelay = min(currentDelay + 10, 200); // Increase delay by 10 every second, capped at 200
//delay(50);
}
}
You are on the right track but you are kinda fighting with the main loop()!
Firstly you are declaring variables like currentDelay inside the loop() so every time the loop starts another cycle it will reset the variables.
Also you are making the code "blocking" by introducing things like "delay()" and a "while" loop inside which means that no other code can get executed after the while loop for at least a second.
Here is a quick example of what I think you want to achieve in a more non-blocking way.