# First code (tweak). Simple strobe

I took the white fade pattern, changed the wave to square, used t2 as the duty (t2 seems unused in original?), then dialed down the times until I got a nice snappy strobe effect… However I am getting very irregular strobing, particularly on faster cycles… Is this a limitation or something to do with the lack of fixed framerate? It also appears to be quite dim, do leds have a “warm up” time?

Here is “my” code:

export function beforeRender(delta) {
t1 = time(.001)
t2 = time(9000)
}

export function render(index) {
h = 1
v = square(t1,t2)
hsv(h,0,v)
}

@Robinlawrie, excellent! Diving in and changing code to see what happens is the best way to learn, and one of the most fun things about Pixelblaze. You’ve almost got it - let me just add a little clarification on time() and square().

Time(interval) makes a sawtooth wave at a frequency of 65.535*interval. So for t1, which you’re using to set the frequency of your flash, an interval of 0.001 would be about 15 times a second, which is probably a little too fast. Maybe try 0.005, which will be about 3 times per second, to start.

For t2, the duty cycle (or percentage of the time the lights will be “on”) you don’t actually need time() at all, and the time() of 9000 is going to cause trouble because the timespan is so long - zero to 1 over 65.536*9000 = 585,815 seconds. That’s um, quite a while.

That means for the first few hours of your run, the duty cycle value will be very close to zero, which means the lights won’t be on for very much of the cycle. That will make them dim, and combined with the very high flash frequency, could make the flashing erratic.

Since you probably don’t need to vary the duty cycle over time anyway, you can simplify things. Try setting t2 to a fixed 0.25, (light is on for 25% of the total flash period) and see if you like how it looks.

After these changes, beforeRender() function will look something like this:

``````export function beforeRender(delta) {
t1 = time(.005) // frequency of flash - lower is faster
t2 = 0.25       // what percentage of the cycle will the light be on?
}
``````
1 Like

Ahh yes, that will be it, the unnecessary time() for t2…

I thought 9000 looked an odd value for the duty cycle, but I arrived at it by trying various numbers…i assumed it should be somewhere between 0 and 1, but with time () included, those values didn’t work.