-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from MisterZeus/add-kitt-example
add kitt.py to examples
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
|
||
from sys import exit # so the blinkt lights can turn off | ||
import time # so we can wait between frames | ||
import blinkt # so we can talk to our blinkt lights! | ||
|
||
BRIGHTNESS = 0.2 # range is 0.0 to 1.0 | ||
MAX_COLOUR = 255 # range is 0 to 255 | ||
DECAY_FACTOR = 1.5 # how quickly should MAX_COLOUR fade? (1.5 works well) | ||
TIME_SLEEP = 0.04 # seconds (0.04 works well) | ||
|
||
PIXELS = blinkt.NUM_PIXELS # usually 8, can use fewer if you like! | ||
|
||
blinkt.clear # make all pixels blank / black | ||
blinkt.set_brightness(BRIGHTNESS) | ||
|
||
brightpixel = -1 | ||
direction = 1 | ||
|
||
print('Hello Michael.\nHow are you today?') | ||
|
||
while True: | ||
# decay all pixels | ||
for x in range(PIXELS): | ||
pixel = blinkt.get_pixel(x) # format is [ r, g, b, brightness? ] | ||
blinkt.set_pixel(x, pixel[0] / DECAY_FACTOR, 0, 0) | ||
|
||
# brightpixel should move back and forth all the pixels, | ||
# in a ping-pong, triangle wave. Not (co)sine. | ||
brightpixel += direction | ||
|
||
if brightpixel >= PIXELS - 1: | ||
brightpixel = PIXELS - 1 | ||
direction = - abs(direction) | ||
if brightpixel <= 0: | ||
brightpixel = 0 | ||
direction = abs(direction) | ||
|
||
blinkt.set_pixel(brightpixel, MAX_COLOUR, 0, 0) | ||
|
||
blinkt.show() # draw the lights! | ||
time.sleep(TIME_SLEEP) # wait a bit before working on next frame |