Theater Chase
Theater Chase is a classic pattern that was popularized in marquee signs above movie theaters. It consists of a row of lights that were usually switched on and off so it would appear that the lights were moving or being chased around the edge of the signs.
Sample Theater Chase Function
To create the illusion of pixels moving along a strip, we need to have three nested loops:
- The inner "i" loop just moves from 0 to the number of pixels in steps of 3 (or a similarly small number). It turns every 3rd pixel on, waits and then turns it off
- The middle "q" loop just offsets the starting point of the inner loop moving from values of 0, 1 and 2. The index in the inner loop is
i+q
. - The outer-most "j" loop just indicates how many times the pattern should be repeated
Here is a sample of the theater_chase
function that has four parameters:
- the LED strip
- the color
- the delay (about 50 milliseconds)
- the number of times the pattern should be repeated (iterations)
1 2 3 4 5 6 7 8 9 10 11 12 |
|
If you want to lower the power of the LED strip, you can change the skip number in the inner loop from 3 to 4, 5 or 6 etc.
Full Program
This program will run a theater chase for the seven colors of the rainbow and then repeat.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
Exercises
- Add the skip number as an additional parameter to the function
- Add another parameter that reversed the direction of the movement
- Create a function that randomly changes the direction every few seconds