code.py
 1  # SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """CircuitPython Essentials Storage logging example"""
 6  import time
 7  import board
 8  import digitalio
 9  import microcontroller
10  
11  # For most CircuitPython boards:
12  led = digitalio.DigitalInOut(board.LED)
13  # For QT Py M0:
14  # led = digitalio.DigitalInOut(board.SCK)
15  led.switch_to_output()
16  
17  try:
18      with open("/temperature.txt", "a") as fp:
19          while True:
20              temp = microcontroller.cpu.temperature
21              # do the C-to-F conversion here if you would like
22              fp.write('{0:f}\n'.format(temp))
23              fp.flush()
24              led.value = not led.value
25              time.sleep(1)
26  except OSError as e:  # Typically when the filesystem isn't writeable...
27      delay = 0.5  # ...blink the LED every half second.
28      if e.args[0] == 28:  # If the file system is full...
29          delay = 0.25  # ...blink the LED faster!
30      while True:
31          led.value = not led.value
32          time.sleep(delay)