47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import pygame
|
|
import lib.pgfw.pgfw as pgfw
|
|
|
|
try:
|
|
import RPi.GPIO as GPIO
|
|
rpi_available = True
|
|
except ImportError:
|
|
rpi_available = False
|
|
|
|
TRIGGER_PIN = 37
|
|
|
|
|
|
class TriggerTest(pgfw.Game):
|
|
|
|
def __init__(self):
|
|
pgfw.Game.__init__(self)
|
|
self.subscribe(self.respond)
|
|
self.register(self.end_output_signal)
|
|
|
|
def respond(self, event):
|
|
if self.delegate.compare(event, "down"):
|
|
if rpi_available:
|
|
GPIO.output(TRIGGER_PIN, GPIO.HIGH)
|
|
self.play(self.end_output_signal, play_once=True, delay=500)
|
|
self.suppress_input_temporarily()
|
|
|
|
def end_output_signal(self):
|
|
if rpi_available:
|
|
GPIO.output(TRIGGER_PIN, GPIO.LOW)
|
|
print("End output signal")
|
|
|
|
def update(self):
|
|
pgfw.Animation.update(self)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if rpi_available:
|
|
# Use physical board header numbering
|
|
GPIO.setmode(GPIO.BOARD)
|
|
|
|
# Set the pin that will trigger the dispenser as an output, but not sending a signal yet
|
|
GPIO.setup(TRIGGER_PIN, GPIO.OUT, initial=GPIO.LOW)
|
|
|
|
game = TriggerTest()
|
|
game.run()
|