/ GemmaM0_Headband / code.py
code.py
1 # SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 # Gemma M0 Onchip Temperature Sensor 6 # Project by Kathy Ceceri 7 # CircuitPython by Anne Barela 8 # Adafruit Industries, 2019 9 10 import time 11 import board 12 import microcontroller 13 import neopixel 14 import adafruit_dotstar 15 16 ROOM_TEMP = 65.0 # Set this to the temp to change from blue to red (F) 17 18 # Set up NeoPixel strand 19 pixels = neopixel.NeoPixel(board.D1, # NeoPixels on pin D1 20 4, # Number of Pixels 21 brightness=0.2) # Change from 0.0 to 1.0 22 23 # For the Gemma M0 onboard DotStar LED 24 dotstar = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1) 25 26 def deg_f(deg_c): # Convert Celcius to Fahrenheit 27 return(deg_c * 9 / 5) + 32.0 28 29 while True: 30 temp = deg_f(microcontroller.cpu.temperature) 31 if temp > ROOM_TEMP: 32 pixels.fill((255, 0, 0)) # (255,0,0) is red 33 dotstar.fill((255, 0, 0)) # Set to red 34 else: 35 pixels.fill((0, 0, 255)) # (0,0,255) is blue 36 dotstar.fill((0, 0, 255)) # Set to blue 37 38 time.sleep(1.0) # Wait 1 second