#!/usr/bin/env python print(""" Analog-Sensor LM35 (analog 1) Photoresistor (analog 2) Schalter 3: Script beenden Schalter 4: System herunterfahren Press CTRL+C to exit """) import explorerhat import time import sys import os status = "0" # 0=weiter 8=script beenden 9=shutdown touched = [False] * 8 def ohai(channel, event): touched[channel - 1] = True print("{}: {}".format(channel, event)) def ScriptEnde(channel, event): global status status = "8" def ShutDown(channel, event): global status status = "9" explorerhat.touch.one.pressed(ohai) explorerhat.touch.three.pressed(ScriptEnde) explorerhat.touch.four.pressed(ShutDown) # Muster für alle # explorerhat.touch.released(ohai) # Farben: blau, gelb, rot, grün # Test der Lämpchen explorerhat.light[0].on() time.sleep(1) explorerhat.light[1].on() time.sleep(1) explorerhat.light[2].on() time.sleep(1) explorerhat.light[3].on() time.sleep(1) explorerhat.light.toggle() # Alle wieder AUS time.sleep(2) A1_mV_a = 0.0 A2_mV_a = 0.0 while status == "0": Uhrzeit = time.localtime() A1_mV = explorerhat.analog.one.read()*1000 A2_mV = explorerhat.analog.two.read()*1000 if A1_mV != A1_mV_a or A2_mV != A2_mV_a: print(Uhrzeit[3],":",Uhrzeit[4],":",Uhrzeit[5]) print("A1 (mV) :", A1_mV, " Temp C° :", A1_mV/10, " A2 (mV) :", A2_mV) A1_mV_a = A1_mV A2_mV_a = A2_mV time.sleep(1) explorerhat.pause time.sleep(2) print("Abfrageschleife beendet") if status == "9": explorerhat.light.red.blink(.3,.1) print("System wir heruntergefahren") time.sleep(3) explorerhat.light.red.on() os.system("sudo shutdown -h now") if status == "8": explorerhat.light.red.blink(.3,.3) print("Script wird beendet") time.sleep(3) explorerhat.light.red.off() sys.exit() print("Script beendet")