|
1 | 1 | import time
|
2 | 2 |
|
3 |
| -from adafruit_circuitplayground.express import cpx |
| 3 | +from adafruit_circuitplayground import cp |
4 | 4 |
|
5 | 5 | # Red, green, blue, and simple mixes of 2 or 3.
|
6 | 6 | # Add your own choices here.
|
|
30 | 30 | brightness_step = 2
|
31 | 31 | color_index = 0
|
32 | 32 | num_pixels = 2
|
33 |
| -cpx.pixels.auto_write = False |
| 33 | +cp.pixels.auto_write = False |
34 | 34 |
|
35 | 35 | while True:
|
36 |
| - if cpx.light > TURN_OFF: |
| 36 | + if cp.light > TURN_OFF: |
37 | 37 | # Indicate the nightlight is off.
|
38 |
| - cpx.red_led = True |
| 38 | + cp.red_led = True |
39 | 39 | continue
|
40 | 40 | else:
|
41 |
| - cpx.red_led = False |
| 41 | + cp.red_led = False |
42 | 42 |
|
43 | 43 | # Decrease brightness.
|
44 |
| - if cpx.touch_A7: |
| 44 | + if cp.touch_A7: |
45 | 45 | # Don't go below 1.
|
46 | 46 | brightness_step = max(1, brightness_step - 1)
|
47 | 47 |
|
48 | 48 | # Increase brightness.
|
49 |
| - if cpx.touch_A6: |
| 49 | + if cp.touch_A6: |
50 | 50 | # Don't go above BRIGHTNESS_STEPS.
|
51 | 51 | brightness_step = min(BRIGHTNESS_STEPS, brightness_step + 1)
|
52 | 52 |
|
53 | 53 | # Change color.
|
54 |
| - if cpx.touch_A3: |
| 54 | + if cp.touch_A3: |
55 | 55 | # Cycle through 0 to len(COLORS)-1 and then wrap around.
|
56 | 56 | color_index = (color_index + 1) % len(COLORS)
|
57 | 57 |
|
58 | 58 | # Increase number of pixels.
|
59 |
| - if cpx.touch_A5: |
| 59 | + if cp.touch_A5: |
60 | 60 | # Don't go below 1.
|
61 | 61 | num_pixels = max(1, num_pixels - 1)
|
62 | 62 |
|
63 | 63 | # 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). |
66 | 66 | num_pixels = min(10, num_pixels + 1)
|
67 | 67 |
|
68 | 68 |
|
69 | 69 | # 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 |
71 | 71 | for i in range(num_pixels):
|
72 |
| - cpx.pixels[i] = COLORS[color_index] |
| 72 | + cp.pixels[i] = COLORS[color_index] |
73 | 73 | 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() |
76 | 76 |
|
77 | 77 | time.sleep(0.2)
|
0 commit comments