Skip to content

Commit f042c59

Browse files
authored
Merge pull request #75 from kattni/remove-simpleio
Remove need for simpleio.
2 parents 59850fb + 739c78b commit f042c59

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

examples/circuitplayground_light_neopixels.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
2-
This example requires the simpleio.mpy library.
3-
4-
This example uses the light sensor on the CPX, located net to the picture of the eye on the board.
1+
"""
2+
This example uses the light sensor on the CPX, located next to the picture of the eye on the board.
53
Once you have the library loaded, try shining a flashlight on your CPX to watch the number of
6-
NeoPixels lit up increase, or try covering up the light sensor to watch the number decrease."""
4+
NeoPixels lit up increase, or try covering up the light sensor to watch the number decrease.
5+
"""
6+
77
import time
88
from adafruit_circuitplayground.express import cpx
9-
import simpleio
109

1110
cpx.pixels.auto_write = False
1211
cpx.pixels.brightness = 0.3
1312

13+
14+
def scale_range(value):
15+
"""Scale a value from 0-320 (light range) to 0-10 (the number of NeoPixels).
16+
Allows remapping light value to pixel position."""
17+
return int(value / 320 * 10)
18+
19+
1420
while True:
15-
# light value remapped to pixel position
16-
peak = simpleio.map_range(cpx.light, 0, 320, 0, 10)
21+
peak = scale_range(cpx.light)
1722
print(cpx.light)
1823
print(int(peak))
1924

20-
for i in range(0, 10, 1):
25+
for i in range(10):
2126
if i <= peak:
2227
cpx.pixels[i] = (0, 255, 255)
2328
else:

examples/circuitplayground_temperature_neopixels.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
2-
This example requires the simpleio.mpy library.
3-
1+
"""
42
This example use the temperature sensor on the CPX, located next to the picture of the thermometer
53
on the board. Try warming up the board to watch the number of NeoPixels lit up increase, or cooling
64
it down to see the number decrease. You can set the min and max temperatures to make it more or
75
less sensitive to temperature changes.
86
"""
97
import time
108
from adafruit_circuitplayground.express import cpx
11-
import simpleio
129

1310
cpx.pixels.auto_write = False
1411
cpx.pixels.brightness = 0.3
@@ -17,13 +14,19 @@
1714
minimum_temp = 24
1815
maximum_temp = 30
1916

17+
18+
def scale_range(value):
19+
"""Scale a value from the range of minimum_temp to maximum_temp (temperature range) to 0-10
20+
(the number of NeoPixels). Allows remapping temperature value to pixel position."""
21+
return int((value - minimum_temp) / (maximum_temp - minimum_temp) * 10)
22+
23+
2024
while True:
21-
# temperature value remapped to pixel position
22-
peak = simpleio.map_range(cpx.temperature, minimum_temp, maximum_temp, 0, 10)
25+
peak = scale_range(cpx.temperature)
2326
print(cpx.temperature)
2427
print(int(peak))
2528

26-
for i in range(0, 10, 1):
29+
for i in range(10):
2730
if i <= peak:
2831
cpx.pixels[i] = (0, 255, 255)
2932
else:

0 commit comments

Comments
 (0)