Skip to content

Remove need for simpleio. #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions examples/circuitplayground_light_neopixels.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
This example requires the simpleio.mpy library.

This example uses the light sensor on the CPX, located net to the picture of the eye on the board.
"""
This example uses the light sensor on the CPX, located next to the picture of the eye on the board.
Once you have the library loaded, try shining a flashlight on your CPX to watch the number of
NeoPixels lit up increase, or try covering up the light sensor to watch the number decrease."""
NeoPixels lit up increase, or try covering up the light sensor to watch the number decrease.
"""

import time
from adafruit_circuitplayground.express import cpx
import simpleio

cpx.pixels.auto_write = False
cpx.pixels.brightness = 0.3


def scale_range(value):
"""Scale a value from 0-320 (light range) to 0-10 (the number of NeoPixels).
Allows remapping light value to pixel position."""
return int(value / 320 * 10)


while True:
# light value remapped to pixel position
peak = simpleio.map_range(cpx.light, 0, 320, 0, 10)
peak = scale_range(cpx.light)
print(cpx.light)
print(int(peak))

for i in range(0, 10, 1):
for i in range(10):
if i <= peak:
cpx.pixels[i] = (0, 255, 255)
else:
Expand Down
17 changes: 10 additions & 7 deletions examples/circuitplayground_temperature_neopixels.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"""THIS EXAMPLE REQUIRES A SEPARATE LIBRARY BE LOADED ONTO YOUR CIRCUITPY DRIVE.
This example requires the simpleio.mpy library.

"""
This example use the temperature sensor on the CPX, located next to the picture of the thermometer
on the board. Try warming up the board to watch the number of NeoPixels lit up increase, or cooling
it down to see the number decrease. You can set the min and max temperatures to make it more or
less sensitive to temperature changes.
"""
import time
from adafruit_circuitplayground.express import cpx
import simpleio

cpx.pixels.auto_write = False
cpx.pixels.brightness = 0.3
Expand All @@ -17,13 +14,19 @@
minimum_temp = 24
maximum_temp = 30


def scale_range(value):
"""Scale a value from the range of minimum_temp to maximum_temp (temperature range) to 0-10
(the number of NeoPixels). Allows remapping temperature value to pixel position."""
return int((value - minimum_temp) / (maximum_temp - minimum_temp) * 10)


while True:
# temperature value remapped to pixel position
peak = simpleio.map_range(cpx.temperature, minimum_temp, maximum_temp, 0, 10)
peak = scale_range(cpx.temperature)
print(cpx.temperature)
print(int(peak))

for i in range(0, 10, 1):
for i in range(10):
if i <= peak:
cpx.pixels[i] = (0, 255, 255)
else:
Expand Down