This section provides short two-line examples. But the concepts might be a bit more advanced than that implies. For the brave ones, read ahead!

Random Speed of playback

2 lines.

Not an effect in itself but a kind of seasoning you add to a sequence. It lets you reuse the same custom sequence on other LED Ports and have it look different each time.

A road construction barricade is one example. Arranged several down the street, they should all flash at different times. This makes it so, without creating more sequences. That is because the Morsel uses another copy of the same sequence and puts it in another sequence player. Although each copy contains the same lines of random code, each plays differently, because that’s what randomness is all about. And that makes each LED Port look different.

We start with a barricade that does not have randomness. It is very simple but every copy will flash identically.

//Road Construction Barricade
//Using strobe-like LED's or slow decay incandescents

@0.6s  chn1 = fade from 0% to 100% in 100ms  //On. Incandescent=100ms led=0ms
@0.7s chn1 = fade from 100% to 0% in 100ms  //Off. Incandescent=100ms led=0ms

We can add a snippet of random code where it won’t affect the appearance but will drift over time. Like this.

//sequence randomizer
//randomly skips ahead by a small amount
//every now and then

@+0ms  go to skipForward with 50% chance
@+25ms skipforward                       //when Go To occurs, this much time is snipped out

The @+0ms time stamp is redundant because it does not change the time. It is only provided to make clear to the reader how much the Go To skips forward.

The +25ms figure is meant as a first guess that may need to be adjusted. In a fast cycling effect, that number may be too big. In a slow changing effect, it may be too short to matter. Adjust accordingly.

After a few loops of replaying the sequence, the skipped times add up, though not consistently, and that is the randomness we want.

Random Starting Point

Another way to randomize is to start some copies at a different point in the sequence. Identify an alternate starting point or two to Go To with Chance. The percent chances may be altered if desired.

//Three random starting points
//using two Go To's with Chance

Go To alternateStart3 with 33% chance    //optional third starting point
Go To alternateStart2 with 50% chance    //second starting point

// or it falls through to the original starting point 

loopLabel
// original code starts here

alternateStart2   //label added to original code somewhere

//original code continues

alternateStart3   //label added to original code somewhere

//original code ends with a go to
Go To loopLabel

The Go To alternate starting point statements should be used only once. That means the sequence should not fall through and replay. Use a Go To loopLabel as shown.

Putting it all together

Both random types were added to the construction barricade. We had to add labels and timestamps around the 1/3 and 2/3 points in time.

//Road Construction Barricade
//Slight variation in speed
//plus three starting points

              //Either falls through to the beginning of the loop or
              //goes to alternate starting point
              Go To alternateStart3 with 33% chance
              Go To alternateStart2 with 50% chance

flashLoop
@0.2s            //remove 1/3 the time before first flash
alternateStart2
@0.4s            //remove 2/3 the time before first flash
alternateStart3
               //skips ahead randomly by a small amount now and then 
@+0ms          go to skipForward with 50% chance 
@+25ms         skipforward

@0.6s         //wait the last third of the time before flashing 
              chn1 = fade from 0% to 100% in 100ms //On. Incandescent=100ms led=0ms
@0.7s        //wait an adequate time for either LED or incandescent types
              chn1 = fade from 100% to 0% in 100ms //Off. Incandescent=100ms led=0ms
            
              go to flashLoop   //continue flashing with small random variations

So it seems our construction barricade became quite a bit longer. On the other hand, it could be argued that randomization is a more sophisticated function. Notice too, that we packed all our techniques into a very simple example when a two-line skip ahead 25ms might have sufficed.

Return to Sequence List