I want to use DueTimer.h to read analog values every 200 microseconds and FastLed.h for controlling 2812B led’s. Both work fine separately, but the FastLED.show() instruction on line 17 seems to block the timer. In this program the timer does not function, but the timer does function if I comment the FastLED.show() instruction on line 17. How can I solve this?
#include <DueTimer.h> #include “FastLED.h”
byte Speed_1; // For reading analog pin 4.
CRGB Leds[256]; // Total amount of led’s.
void setup() {
Serial.begin(115200);
FastLED.addLeds<WS2812B, 53, GRB>(Leds, 0, 256);
Read_Analog();
Timer.getAvailable().attachInterrupt(Read_Analog).setFrequency(5).start();
}
void loop() {
Speckle();
}
void Speckle() {
for (int x = 0; x < 256; x++) {
Leds = CHSV(Speed_1, 100, 20);
FastLED.show();
delay(Speed_1);
}
}
void Read_Analog() {
Serial.println(“In read_analog”);
Speed_1 = analogRead(4) / 4;
}
I do not yet have the programming skills to solve a hardware timer clash between libraries, but I found a workaround which does function in my case by simply avoiding the timer library and do the reading of the inputs every time FastLED.show is called, using this code: