Portability to FastLED/Arduino

Hey, friends. New guy here :slight_smile:

I’m considering buying PixelBlaze to develop some LED patterns but wanted to know if anyone has been able to port PixelBlaze code to FastLED (on an Arduino). I have an Arduino project I’m working on that uses the FastLED library, and I intend to have that be the final platform. I’d like to use PixelBlaze to design some patterns and then port the patterns to work on my Arduino. I figured some of the folks here may have experience moving code between the two.

I’ve been trying to reverse engineer some of the trig functions (e.g., time, wave, triangle) that are used in many of the examples, but after implementing what I thought would work, I haven’t successfully gotten the patterns to light up my LED strip. If anyone’s done this before, I’d love to know how you implemented the trig functions.

If anyone’s interested, this is my scrappy Arduino code (just wanted a proof of concept that would work)

float time(float interval)
float t = millis();
float scaling = 10.429049498 * interval; // scaling factor needed to make a
// a sawtooth waveform from 0.0 and 1.0
// that loops about every 65.536*interval seconds

return (fmod(t, 2 * PI * scaling) / (2*PI))/scaling;

float triangle(float t)
return 1.0 - fabs(fmod(2*t, 2.0) - 1.0);

float wave(float v)
return (1 + sin(v * 2*PI)) / 2;

float square(float v)
float sinValue = wave(v);

return sinValue >= 0.5 ? 1 : 0;

Very close! Its all in fixed point math so some might be lost in translation. Time doesn’t have anything to do with PI, but if that works for you and gets the right time period, thats really all that matters. I think the one used by Michael Leibman in this browser version is closer to a straight conversion:

square doesn’t use wave, its just a threshold cutoff after ‘wrapping’

All of them ‘wrap’ like so:

v = fmod(v, 1)
if (v < 0)
 v += 1

Triangle, afer wrapping, is roughly:

v *= 2
result = v < 1 ? v : 2 - v

Let us now how it goes!