Skip to content

Sample: Dot

Let's actually display an image. Here, we use an LED strip with 60 WS2812 LEDs in series to show an animation of a flowing red dot.

  1. Set up the display. Connect the DIN terminal of the LED to GPIO2.
L:/>display-ws2812 setup {din:2 straight:60}
  1. Download the image file red-dot.png. When enlarged, the pixel image looks like this:

red-dot-image Image of red-dot.png

Save this file to the Pico board's internal storage L: drive. When the Pico board is connected to the host PC via USB cable, the L: drive appears as a USB memory device on the host PC, so copy the file there.

  1. Use the image-load subcommand of the draw command to load the image file into the image buffer.
L:/>draw image-load:red-dot.png
  1. Run the image subcommand to display the contents of the image buffer on the display. Here, use the size subcommand to set the display area in the image to 8 x 1.
L:/>draw image {size:8,1}

Only one red LED lights up.

  1. Using the repeat-x subcommand, you can repeat the image across the entire width of the display. Let's check that a red LED lights up every 8 LEDs.
L:/>draw image {size:8,1 repeat-x}
  1. The offset-shift subcommand shifts the display area within the image by a specified amount. The following example shifts the display area 1 pixel to the right.
L:/>draw image {offset-shift:1,0}

This operation changes the display as shown below, making it look like the dot is moving.

red-dot-shifted

Try running it several times to see the red LED move. When the display area reaches the right end, offset-shift wraps it back to the left.

  1. The repeat subcommand repeatedly executes the subcommands inside the braces {}. Press Ctrl-C to stop the repetition.
L:/>draw repeat { image {offset-shift:1,0} }

If the display speed is too fast and all LEDs appear lit, use the sleep subcommand to pause for the specified milliseconds. The following example shifts the display position every 100ms.

L:/>draw repeat { image {offset-shift:1,0} sleep:100 }

The illumination strip is complete!

Here is a summary of the commands to run:

L:/>display-ws2812 setup {din:2 straight:60} brightness:.1
L:/>draw image-load:red-dot.png
L:/>draw image {size:8,1 repeat-x}
L:/>draw repeat { image {offset-shift:1,0} sleep:100 }