Moving Bands of Color
In this lesson, we will create a program that will move a set of bands of color down the LED strip. To do this we will create a function called draw_band(start, end, color)
that will fill a range of pixels with a given color.
1 2 3 4 |
|
This works, but we also have the problem that the last pixel does not get erased
1 2 3 4 5 6 7 8 9 |
|
We can then draw three "bands" of color like this:
1 2 3 |
|
We can make this group of bands appear to move by adding a offset to the start like this:
1 2 3 4 |
|
This will work fine until the value of i plus the offset exceeds the length of the LED strip. To get around this, we should never write to location i by itself. We should always divide i by the strip lenght and write to the remainder, what is call the modulo. We just have to change one line in the draw_band function:
1 2 3 4 |
|