techoverload/controller/main.py

70 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-07-20 11:45:24 +00:00
from gpiozero import LED, Button
from time import sleep
import paho.mqtt.client as mqtt
red = LED(19)
blue = LED(26)
green = LED(13)
button = Button(5)
def main ():
idle = False
while True:
if not idle:
send_idle()
idle = True
sleep(5)
red.on()
send_stop()
if buttonWait():
red.off()
idle = False
playaudio()
displaytext()
sleep(5)
playaudio()
displaytext()
green.on()
printquestion()
sleep(1)
green.off()
red.off()
def buttonWait():
for i in range(500):
if button.value:
print("Button pressed")
return True
sleep(0.01)
return False
def send_idle():
print("Idle")
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("slave", "idle")
def playaudio():
print("Play audio")
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("slave", "audio")
def playvideo():
pass
def displaytext():
print("Display text")
def printquestion():
print("Question")
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("print", "question")
def send_stop():
pass
main()