code.py
 1  # SPDX-FileCopyrightText: 2019 Liz Clark for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  # Adafruit PyPortal display of Twin Peaks
 6  # Liz (BlitzCityDIY) for Adafruit Industries  MIT License
 7  # Tutorial: https://learn.adafruit.com/twin-peaks-light-reactive-pyportal-picture-frame
 8  import time
 9  import board
10  from analogio import AnalogIn
11  from adafruit_pyportal import PyPortal
12  
13  analogin = AnalogIn(board.LIGHT)
14  
15  cwd = ("/"+__file__).rsplit('/', 1)[0]
16  
17  laura = (cwd+"/laura.bmp")
18  
19  woodsman = (cwd+"/woodsman.bmp")
20  
21  gottaLight = (cwd+"/gottaLight.wav")
22  
23  pyportal = PyPortal(default_bg=laura)
24  
25  def getVoltage(pin):  # helper
26      return (pin.value * 3.3) / 65536
27  
28  while True:
29  
30      if getVoltage(analogin) > 0.175:
31          pyportal.set_background(laura)
32          time.sleep(1)
33      else:
34          pyportal.set_background(woodsman)
35          pyportal.play_file(gottaLight)
36          time.sleep(1)