Skip to content

Commit

Permalink
Merge pull request #94 from MisterZeus/add-kitt-example
Browse files Browse the repository at this point in the history
add kitt.py to examples
  • Loading branch information
Gadgetoid committed Jan 31, 2022
2 parents 8fa9928 + cf542eb commit 228a30b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/kitt.py
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

0 comments on commit 228a30b

Please sign in to comment.