Back to: Multiplier Event Luxembourg
import time
from adafruit_circuitplayground import cp
# Set values based on the user’s ambient temperature measured in degrees Celsius.
temperature_min = 20
temperature_max = 40
# Loop forever
while True:
scale = round(10 * (cp.temperature - temperature_min) / (temperature_max - temperature_min))
# Get through NeoPixels #0 to #9.
for p in range(10):
if p < scale:
cp.pixels[p] = (255, 255, 255) # (Turn on the NeoPixel.)
else:
cp.pixels[p] = (0, 0, 0) # (Turn off the NeoPixel.)
# Depending on the switch, write to
# * the serial console (if True, i.e. left), or to
# * the CircuitPython storage (if False, i.e. right).
if cp.switch:
print("Temperature is", "{:.2f}".format(cp.temperature), "°C scaled to", scale, "in [", temperature_min, "°C,", temperature_max, "°C ]")
print( (cp.temperature, scale, temperature_min, temperature_max) )
else:
f = open("temperature.csv", "a")
f.write(repr(cp.temperature) + "," + repr(scale) + "," + repr(temperature_min) + "," + repr(temperature_max) + "\n")
f.close()
# Sleep 1 second to slow down the readings.
time.sleep(1)
import storage
from adafruit_circuitplayground import cp
storage.remount("/", readonly=cp.switch)
