|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | | -from sys import exit # so the blinkt lights can turn off |
4 | 3 | import time # so we can wait between frames |
5 | 4 | import blinkt # so we can talk to our blinkt lights! |
6 | 5 |
|
|
9 | 8 | DECAY_FACTOR = 1.5 # how quickly should MAX_COLOUR fade? (1.5 works well) |
10 | 9 | TIME_SLEEP = 0.04 # seconds (0.04 works well) |
11 | 10 |
|
12 | | -PIXELS = blinkt.NUM_PIXELS # usually 8, can use fewer if you like! |
| 11 | +PIXELS = blinkt.NUM_PIXELS # usually 8, can use fewer if you like! |
13 | 12 |
|
14 | | -blinkt.clear # make all pixels blank / black |
| 13 | +blinkt.clear # make all pixels blank / black |
15 | 14 | blinkt.set_brightness(BRIGHTNESS) |
16 | 15 |
|
17 | 16 | brightpixel = -1 |
|
20 | 19 | print('Hello Michael.\nHow are you today?') |
21 | 20 |
|
22 | 21 | while True: |
23 | | - # decay all pixels |
24 | | - for x in range(PIXELS): |
25 | | - pixel = blinkt.get_pixel(x) # format is [ r, g, b, brightness? ] |
26 | | - blinkt.set_pixel(x, pixel[0] / DECAY_FACTOR, 0, 0) |
27 | | - |
28 | | - # brightpixel should move back and forth all the pixels, |
29 | | - # in a ping-pong, triangle wave. Not (co)sine. |
30 | | - brightpixel += direction |
31 | | - |
32 | | - if brightpixel >= PIXELS - 1: |
33 | | - brightpixel = PIXELS - 1 |
34 | | - direction = - abs(direction) |
35 | | - if brightpixel <= 0: |
36 | | - brightpixel = 0 |
37 | | - direction = abs(direction) |
38 | | - |
39 | | - blinkt.set_pixel(brightpixel, MAX_COLOUR, 0, 0) |
40 | | - |
41 | | - blinkt.show() # draw the lights! |
42 | | - time.sleep(TIME_SLEEP) # wait a bit before working on next frame |
| 22 | + # decay all pixels |
| 23 | + for x in range(PIXELS): |
| 24 | + pixel = blinkt.get_pixel(x) # format is [ r, g, b, brightness? ] |
| 25 | + blinkt.set_pixel(x, pixel[0] / DECAY_FACTOR, 0, 0) |
| 26 | + |
| 27 | + # brightpixel should move back and forth all the pixels, |
| 28 | + # in a ping-pong, triangle wave. Not (co)sine. |
| 29 | + brightpixel += direction |
| 30 | + |
| 31 | + if brightpixel >= PIXELS - 1: |
| 32 | + brightpixel = PIXELS - 1 |
| 33 | + direction = - abs(direction) |
| 34 | + if brightpixel <= 0: |
| 35 | + brightpixel = 0 |
| 36 | + direction = abs(direction) |
| 37 | + |
| 38 | + blinkt.set_pixel(brightpixel, MAX_COLOUR, 0, 0) |
| 39 | + |
| 40 | + blinkt.show() # draw the lights! |
| 41 | + time.sleep(TIME_SLEEP) # wait a bit before working on next frame |
0 commit comments