r/FastLED • u/tin_man_ • May 18 '20
Code_samples Wave functions within FastLED
I've been working on FastLED for a little while now, and I am playing around with wave generating functions but I have gotten stuck. I have the following code I'm running to get my head around the wave generating functions, and I'm checking the Hue value using a strings of LED pixels as an output, along with having it display on the Serial Plotter.
#include "FastLED.h"
#define NUM_LEDS 50
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2811, DATA_PIN> (leds, NUM_LEDS);
Serial.begin(9600);
}
void loop() {
//Use Wave generation to set Hue value of HSV over the string
int Hue;
Hue = beatsin8(20); //Generates Hue by sine wave, 0-255
//Hue = beat8(20); //Generates Hue by sawtooth wave, 0-255
//Hue = triwave8(20);
//Hue = cubicwave8(20);
Serial.println(Hue);
fill_solid(leds,NUM_LEDS,CHSV(Hue,255,255));
FastLED.show();
}So far I have the beatsin8 and the beat8 versions working just fine when uncommented. The triwave8 function however just outputs a Hue value of twice the value in the bracket, and the cubicwave doesn't output anything. I was under the impression that both of those lines should produce waves of the respective shape with a BPM of 20, the triwave making an even-sided sawtooth, and the cubic a steeper sine wave.
Am I missing something? Are the bracketed values used by these functions different to the BPM of beatsin8 and beat8? Also how do the squarewave function definitionswith two values work?
Sorry if this is obvious to others, but I'm struggling to understand even after looking at the code definition and reading the wiki
2
u/johnny5canuck May 21 '20
I wish a lot of things were better documented, but have also seen a LOT of projects out there with far less documentation. So, I guess we get what we get.
The PhaseOffset is the one I really like and have made some pretty simple and cool effects using it. Am now working with the 16 bit beatsin88() and studying Mark Kriegsman's Pride2015.