Larson Scanner
The Larson Scanner is a light pattern special effect named after Glen A. Larson. Larson used this pattern to give his Battlestar Galactica Cylon and KITT robot eyes a sense of sentience. See Knight Rider for the backstory.
Description
A set of usually red pixels moves back and forth over the LED strip. The pixels are brighter in the center and are dimmer at the edges of the set. You can see an example of this in the Larson Scanner Pumpkin Kit
Color RGB values
We will need a set of predefined colors for various brightness of red:
red = (255, 0, 0)
red_med = (32, 0, 0)
red_light = (8, 0, 0)
off = (0,0,0)
Note that the color levels are not linear. You can adjust these and add more intermediate levels for wider patterns.
Full Source Code
# Larson Scanner - five pixels
from machine import Pin
from neopixel import NeoPixel
from utime import sleep
NEOPIXEL_PIN = 0
NUMBER_PIXELS = 60
strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
red = (255, 0, 0)
red_med = (32, 0, 0)
red_light = (8, 0, 0)
off = (0,0,0)
delay = .05
while True:
# forward loop
for i in range(2, NUMBER_PIXELS-2):
strip[i-2] = red_light
strip[i-1] = red_med
strip[i] = red
strip[i+1] = red_med
strip[i+2] = red_light
# erase the trailing pixel
if i > 0:
strip[i-3] = off
strip.write()
sleep(delay)
# backward loop
for i in range(NUMBER_PIXELS-4, 1, -1):
# erase the trailing pixel
if i < NUMBER_PIXELS-2:
strip[i+3] = off
strip[i-2] = red_light
strip[i-1] = red_med
strip[i] = red
strip[i+1] = red_med
strip[i+2] = red_light
strip.write()
sleep(delay)
Exercises
- Turn the code into a function with delay as a patter
- Add a color parameter
- Add a parameter for the width of the pattern