Hi All - I've looked through the FastLED docs, Arduino forums and also Google but I haven't found an answer to how the FastLED beatsin8 function updates it's return value between successive calls.
The below code works, but I do not see how beatsin8 returns different values between loops, when it is called with the same initial parameters. I am used to having to call a function with parameters that are updated by the sketch.
But with beatsin8 it seems that it is like a callback, where it is called/updated by the beatsin8 function itself. Otherwise, it would be returning the same brightness value each time through the loop because none of the parameters (beats, low value, high value) are changed by the sketch for the next call.
Any help is very much appreciated.
#include <FastLED.h>
#define DATA_PIN 4
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 10
#define BRIGHTNESS 96
CRGB leds[NUM_LEDS];
void setup() {
delay(1000); // 3 second delay for recovery
Serial.begin(115200);
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
// Get a value between 50 and 200 that changes over time
uint8_t brightness = beatsin8(120, 50, 200);
// Set the pixel's color and brightness
leds[0] = CHSV(0, 255, brightness); // Red with the calculated brightness
// Show the LEDs
FastLED.show();
}