I’m feeling mentally slow here. Can someone explain the wave functions in a bit more practical detail? I’m still at a loss after reading this:
Actually, scratch that. I figured it out. In this case, I’d like to make a documentation/wiki request. For me, it was not intuitive what sin8 was going to return. I just cycled through an input variable, plotted the results, and now get it.
It’s converting 0-255 into the equivalent of a unit circle (like the angle, 2pi * input/255) and then spitting out sin(angle) * 255 to get the 0-255 output. (Well, to reverse engineer it I added 1 to the sin() result to get an output of 0 to 2 instead of -1 to 1, and then multiplied by 255/2.)
Given this, how do folks generally use this? I’m coming from heavy beatsin8() usage which is great. Do you just have to constantly increment some variable and feed it into these functions? Any reason not to implement a beatsin8 equivalent for these? It would seem awesome to just supply a bpm vs. incrementing the input at the desired time (I’d probably use EVERY_N_MILLISECONDS for this?).
Thanks for any input!
i was having similar issues, but i post in support about every 3 days… so i just clumsied along…
i found that sin8(millis()) returns a figure from 0-255, and from here i was using the data like /4 to slow down etc.
also,
EVERY_N_MILLISECONDS( 10 ) { // to call the function
pos=map(sin8(millis()/80), 0, 255, 0, NUM_LEDS);
// pos is the led position (or the relevant led)
// the /80 in this instance slows the sin right down to a smooth display.
// the map assigns the 0-255 to the relevant number of leds in the sequence
leds[pos] += CHSV (hue, 255, 255);
// just choosing the colour
Serial.print(" pos: "); Serial.print(pos);
// text output for reference
}
apart from that, im lost!
Cool, so I’m not the only one.
This also confirms that a beats_something() function to match these would be a pretty natural extension if others are doing what you are. To use the functions you’ve got a lot of code just to figure out the millis and then divide to get the right rate you want.
Since you’re using sin8(), I actually think you’d be better off doing:
pos = beatsin8(bpm, 0, NUM_LEDS - 1)
That’s basically what you’re doing anyway and illustrates why beatsin8 is so much handier. You get the ability to specify min/max and a rate.
Can you try the above and let me know if it does similarly? Just play with bpm until the rate seems right.
(Aside: I think you want to map to NUM_LEDS - 1 since you’re calling by name and the array index will only go to NUM_LEDS - 1).
I think perhaps adding a picture to the docs might help. A graph. I’ll put that in the todo queue.
Awesome. Technically there is a graph; adding x axis labels (and perhaps a function) would be my request. Thanks!
Out of curiosity, am I right that beatsin8 and sin8/beat8 are related? If so, I’d be willing to try making analogs to beatsin8 for the other wave functions. If folks are just using millis and dividing manually to get a desired rate, this seems like a good fit, at least to me?