Dotstar LEDs are individually addressable LED strips for use with Arduinos, Raspberry Pis, and the Minnowboard. It connects to the device through the SPI pins and is driven here by Python.
Start by importing the class file for the LEDs:
In [ ]:
from pyDrivers import dotstar
You can pass several arguments to the Dotstar class constructor to change the behavior of the LED class.
ds = dotstar.Dotstar(led_count=72, bus=0, init_data=0, init_brightness=0)
led_count = some_number_of_leds
Change the number of LEDs in your strip. Note that this counts the raw number of individual LEDs, not how many strips/devices you have. Make sure this is set so all the LEDs are used.
bus = 0
Change the SPI bus. If you do not specify one, it will be initialized on bus 0, which is the default for the Minnowboard.
init_data = some_brightness_value + some_hue
Change the initial value of the LED strip. By default all the LEDS are initialized to the first color pushed. If you plan on having all the LEDs start off dark, don't set anything here.
init_brightness = some_brightness
Change the initial brightness of the LEDs. Valid brightness settings range from 0 to 10, representing the intensity of the LEDs from 0% to 100%. If you want the LEDs to start off dark, set this to 0 at the start.
Here is a typical initialization, starting all 72 LEDS (or 2 Adafruit Dotstar LED strips connected together) turned off:
In [ ]:
ds = dotstar.Dotstar(led_count=72*3,init_brightness=0)
Now we can make use of the functions in the class to set the colors and intesnity of each LED. The class works by populating a deque with the LED values you want, and then pushing all the data at once to the LED strip. The following methods provide the most basic functionality:
Dotstar.set(which_LED, brightness_level, red_hue, blue_hue, green_hue)
This function will add the LED to activate to the queue. The brightness and hue options are on a scale of 0 to 256, and the LED selection is from 0 to
Dotstar.draw()
This funciton draws the created deque to the LED strip. This function will clear the current deque, allowing you to populate another one.
Run this section to create a sequence of 5 red LEDS that move throughout the length of the LEDs. It looks like the LED array on KITT from Knight Rider.
In [ ]:
while True:
for current_led in range (4, ds.led_count-4):
ds.set(current_led-4, 0, 0, 0, 0)
ds.set(current_led-2, 10, 100, 0, 0)
ds.set(current_led-1, 50, 200, 0, 0)
ds.set(current_led, 50, 250, 0, 0)
ds.set(current_led+1, 50, 200, 0, 0)
ds.set(current_led+2, 50, 150, 0, 0)
ds.set(current_led+4, 0, 0, 0, 0)
ds.draw()
for current_led in range(ds.led_count-5, 4, -1):
ds.set(current_led-3,10,100,0,0)
ds.set(current_led-2,10,150,0,0)
ds.set(current_led-1,50,200,0,0)
ds.set(current_led,50,250,0,0)
ds.set(current_led+1,50,200,0,0)
ds.set(current_led+2,50,150,0,0)
ds.set(current_led+4,0,0,0,0)
ds.draw()