-
Notifications
You must be signed in to change notification settings - Fork 769
/
code.py
80 lines (59 loc) · 1.79 KB
/
code.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# SPDX-FileCopyrightText: 2017 Mikey Sklar for Adafruit Industries
#
# SPDX-License-Identifier: MIT
#
# Kaleidoscope_Eyes_NeoPixel_LED_Goggles.py
#
import time
import board
import neopixel
try:
import urandom as random # for v1.0 API support
except ImportError:
import random
numpix = 32 # Number of NeoPixels
pixpin = board.D0 # Pin where NeoPixels are connected
mode = 0 # Current animation effect
offset = 0 # Position of spinny eyes
rgb_colors = ([255, 0, 0], # red
[0, 255, 0], # green
[0, 0, 255]) # blue
rgb_idx = 0 # index counter - primary color we are on
color = rgb_colors[rgb_idx]
prevtime = 0
pixels = neopixel.NeoPixel(pixpin, numpix, brightness=.3, auto_write=False)
prevtime = time.monotonic()
while True:
i = 0
t = 0
# Random sparks - just one LED on at a time!
if mode == 0:
i = random.randint(0, (numpix - 1))
pixels[i] = color
pixels.write()
time.sleep(0.01)
pixels[i] = (0, 0, 0)
# Spinny wheels (8 LEDs on at a time)
elif mode == 1:
for i in range(0, numpix):
c = 0
# 4 pixels on...
if ((offset + i) & 7) < 2:
c = color
pixels[i] = c # First eye
pixels[(numpix - 1) - i] = c # Second eye (flipped)
pixels.write()
offset += 1
time.sleep(0.05)
t = time.monotonic()
if (t - prevtime) > 8: # Every 8 seconds...
mode += 1 # Next mode
if mode > 1: # End of modes?
mode = 0 # Start modes over
if rgb_idx > 2: # reset R-->G-->B rotation
rgb_idx = 0
color = rgb_colors[rgb_idx] # next color assignment
rgb_idx += 1
for i in range(0, numpix):
pixels[i] = (0, 0, 0)
prevtime = t