|
1 | 1 | import time |
2 | 2 | import board |
| 3 | +import microcontroller |
3 | 4 | import displayio |
4 | 5 | import busio |
5 | 6 | from analogio import AnalogIn |
|
12 | 13 | from adafruit_pyportal import PyPortal |
13 | 14 |
|
14 | 15 | # ------------- Inputs and Outputs Setup ------------- # |
15 | | -# init. the temperature sensor |
16 | | -i2c_bus = busio.I2C(board.SCL, board.SDA) |
17 | | -adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) |
18 | | -adt.high_resolution = True |
| 16 | +try: # attempt to init. the temperature sensor |
| 17 | + i2c_bus = busio.I2C(board.SCL, board.SDA) |
| 18 | + adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) |
| 19 | + adt.high_resolution = True |
| 20 | +except ValueError: |
| 21 | + # Did not find ADT7410. Probably running on Titano or Pynt |
| 22 | + adt = None |
19 | 23 |
|
20 | 24 | # init. the light sensor |
21 | 25 | light_sensor = AnalogIn(board.LIGHT) |
@@ -332,9 +336,13 @@ def switch_view(what_view): |
332 | 336 | while True: |
333 | 337 | touch = ts.touch_point |
334 | 338 | light = light_sensor.value |
335 | | - tempC = round(adt.temperature) |
336 | | - tempF = tempC * 1.8 + 32 |
337 | 339 |
|
| 340 | + if adt: # Only if we have the temperature sensor |
| 341 | + tempC = round(adt.temperature) |
| 342 | + else: # No temperature sensor |
| 343 | + tempC = round(microcontroller.cpu.temperature) |
| 344 | + |
| 345 | + tempF = tempC * 1.8 + 32 |
338 | 346 | sensor_data.text = 'Touch: {}\nLight: {}\n Temp: {}°F'.format(touch, light, tempF) |
339 | 347 |
|
340 | 348 | # ------------- Handle Button Press Detection ------------- # |
|
0 commit comments