/ examples / circuitplayground_temperature_neopixels.py
circuitplayground_temperature_neopixels.py
 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 use the temperature sensor on the CPX, located next to the picture of the thermometer
 5  on the board. Try warming up the board to watch the number of NeoPixels lit up increase, or cooling
 6  it down to see the number decrease. You can set the min and max temperatures to make it more or
 7  less sensitive to temperature changes.
 8  """
 9  import time
10  from adafruit_circuitplayground.express import cpx
11  import simpleio
12  
13  cpx.pixels.auto_write = False
14  cpx.pixels.brightness = 0.3
15  
16  # Set these based on your ambient temperature in Celsius for best results!
17  minimum_temp = 24
18  maximum_temp = 30
19  
20  while True:
21      # temperature value remapped to pixel position
22      peak = simpleio.map_range(cpx.temperature, minimum_temp, maximum_temp, 0, 10)
23      print(cpx.temperature)
24      print(int(peak))
25  
26      for i in range(0, 10, 1):
27          if i <= peak:
28              cpx.pixels[i] = (0, 255, 255)
29          else:
30              cpx.pixels[i] = (0, 0, 0)
31      cpx.pixels.show()
32      time.sleep(0.05)