-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·35 lines (30 loc) · 1.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import board
import neopixel
import time
import random
pixpin = board.D1
numpix = 10
# brightness goes from 0 (no light) to 1.0 (full brightness)
# auto_write=True makes it so you don't have to call strip.write()
# to change a value, but it makes things slower(?)
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3, auto_write=False)
# this will be used as in incrementor, to keep track of which neopixel
# we are currently looking at
i = 0
# this just turns off all of the neopixels to start
# it is nice for making sure the code updated :)
strip.fill((0, 0, 0))
while True:
# set the current LED to a random color of purple
# red is a random value between 120 and 255
# green is zero
# blue is a random value between 120 and 255
strip[i] = (random.randrange(120, 255, 1), 0, random.randrange(120, 255, 1))
strip.write()
# wait a second
time.sleep(1)
# move on to the next neopixel in the strip
i = i + 1
# if incrementing i took us past the end of the strip, go back to start
if i >= numpix:
i = 0