Skip to content

Commit 5a5c25f

Browse files
authored
Use more modern CP library conventions.
1 parent 3fb4c22 commit 5a5c25f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Nightlight/cpx_nightlight.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22

3-
from adafruit_circuitplayground.express import cpx
3+
from adafruit_circuitplayground import cp
44

55
# Red, green, blue, and simple mixes of 2 or 3.
66
# Add your own choices here.
@@ -30,48 +30,48 @@
3030
brightness_step = 2
3131
color_index = 0
3232
num_pixels = 2
33-
cpx.pixels.auto_write = False
33+
cp.pixels.auto_write = False
3434

3535
while True:
36-
if cpx.light > TURN_OFF:
36+
if cp.light > TURN_OFF:
3737
# Indicate the nightlight is off.
38-
cpx.red_led = True
38+
cp.red_led = True
3939
continue
4040
else:
41-
cpx.red_led = False
41+
cp.red_led = False
4242

4343
# Decrease brightness.
44-
if cpx.touch_A7:
44+
if cp.touch_A7:
4545
# Don't go below 1.
4646
brightness_step = max(1, brightness_step - 1)
4747

4848
# Increase brightness.
49-
if cpx.touch_A6:
49+
if cp.touch_A6:
5050
# Don't go above BRIGHTNESS_STEPS.
5151
brightness_step = min(BRIGHTNESS_STEPS, brightness_step + 1)
5252

5353
# Change color.
54-
if cpx.touch_A3:
54+
if cp.touch_A3:
5555
# Cycle through 0 to len(COLORS)-1 and then wrap around.
5656
color_index = (color_index + 1) % len(COLORS)
5757

5858
# Increase number of pixels.
59-
if cpx.touch_A5:
59+
if cp.touch_A5:
6060
# Don't go below 1.
6161
num_pixels = max(1, num_pixels - 1)
6262

6363
# Decrease number of pixels.
64-
if cpx.touch_A4:
65-
# Don't go above 10 (number on CPX).
64+
if cp.touch_A4:
65+
# Don't go above 10 (number on Circuit Playgrounds).
6666
num_pixels = min(10, num_pixels + 1)
6767

6868

6969
# Scale brightness to be 0.0 - MAX_BRIGHTNESS.
70-
cpx.pixels.brightness = (brightness_step / BRIGHTNESS_STEPS) * MAX_BRIGHTNESS
70+
cp.pixels.brightness = (brightness_step / BRIGHTNESS_STEPS) * MAX_BRIGHTNESS
7171
for i in range(num_pixels):
72-
cpx.pixels[i] = COLORS[color_index]
72+
cp.pixels[i] = COLORS[color_index]
7373
for i in range(num_pixels, 10):
74-
cpx.pixels[i] = 0
75-
cpx.pixels.show()
74+
cp.pixels[i] = 0
75+
cp.pixels.show()
7676

7777
time.sleep(0.2)

0 commit comments

Comments
 (0)