-
Notifications
You must be signed in to change notification settings - Fork 776
/
Copy pathcode.py
45 lines (36 loc) · 1.08 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
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""CircuitPython Capacitive Touch NeoPixel Brightness Control Example"""
import time
import board
import touchio
import neopixel
from rainbowio import colorwheel
touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)
pixels = neopixel.NeoPixel(board.NEOPIXEL, 4, auto_write=False)
def rainbow(color_index):
for led in range(4):
pixel_index = (led * 256 // 4) + color_index
pixels[led] = colorwheel(pixel_index & 255)
pixels.show()
touched = time.monotonic()
color = 0
while True:
color = color + 1
if color > 255:
color = 0
rainbow(color)
if time.monotonic() - touched < 0.15:
continue
if touch1.value:
# Touch pad 1 to increase the brightness.
pixels.brightness += 0.05
pixels.show()
touched = time.monotonic()
elif touch2.value:
# Touch pad 2 to decrease the brightness.
pixels.brightness -= 0.05
pixels.show()
touched = time.monotonic()