Skip to content

Commit ce1a47f

Browse files
authored
Merge branch 'master' into claw
2 parents 26aa630 + 9dd5e88 commit ce1a47f

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

NeoPixel_Frankenstein/code.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import time
2+
import board
3+
import touchio
4+
import neopixel
5+
from adafruit_led_animation.animation.pulse import Pulse
6+
from adafruit_led_animation.color import (
7+
RED,
8+
YELLOW,
9+
ORANGE,
10+
GREEN,
11+
TEAL,
12+
CYAN,
13+
BLUE,
14+
PURPLE,
15+
MAGENTA,
16+
GOLD,
17+
PINK,
18+
AQUA,
19+
JADE,
20+
AMBER
21+
)
22+
23+
# NeoPixel pin
24+
pixel_pin = board.A3
25+
# number of NeoPixels
26+
pixel_num = 68
27+
28+
# NeoPixels setup
29+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
30+
31+
# animation setup
32+
pulse = Pulse(pixels, speed=0.1, color=RED, period=5)
33+
34+
# two cap touch pins
35+
touch_left = board.A1
36+
touch_right = board.A2
37+
38+
# cap touch setup
39+
bolt_left = touchio.TouchIn(touch_left)
40+
bolt_right = touchio.TouchIn(touch_right)
41+
42+
# NeoPixel colors for animation
43+
colors = [RED, YELLOW, ORANGE, GREEN, TEAL, CYAN, BLUE,
44+
PURPLE, MAGENTA, GOLD, PINK, AQUA, JADE, AMBER]
45+
46+
# variable for color array index
47+
c = 0
48+
49+
# debounce states for cap touch
50+
bolt_left_state = False
51+
bolt_right_state = False
52+
53+
while True:
54+
# run animation
55+
pulse.animate()
56+
57+
# debounce for cap touch
58+
if not bolt_left.value and not bolt_left_state:
59+
bolt_left_state = True
60+
if not bolt_right.value and not bolt_right_state:
61+
bolt_right_state = True
62+
63+
# if the left bolt is touched...
64+
if bolt_left.value and bolt_left_state:
65+
print("Touched left bolt!")
66+
# increase color array index by 1
67+
c += 1
68+
# reset debounce state
69+
bolt_left_state = False
70+
# if the right bolt is touched...
71+
if bolt_right.value and bolt_right_state:
72+
print("Touched right bolt!")
73+
# decrease color array index by 1
74+
c -= 1
75+
# reset debounce state
76+
bolt_right_state = False
77+
# if the color array index is bigger than 13...
78+
if c > 13:
79+
# reset it to 0
80+
c = 0
81+
# if the color array index is smaller than 0...
82+
if c < 0:
83+
# reset it to 13
84+
c = 13
85+
# update animation color to current array index
86+
pulse.color = colors[c]
87+
time.sleep(0.01)
2.59 MB
Binary file not shown.

0 commit comments

Comments
 (0)