Add controller
This commit is contained in:
parent
f9da3a45f0
commit
581fcd8c85
|
@ -0,0 +1,70 @@
|
|||
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()
|
Loading…
Reference in New Issue