-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerButton.py
31 lines (26 loc) · 937 Bytes
/
powerButton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
try:
import RPi.GPIO as GPIO
except:
pass
from states import _start, _searching, _running, _end
class PowerButton:
def __init__(button, bot, pin = 20):
button.buttonPin = pin
button.scaredyBot = bot
try:
GPIO.setmode(GPIO.BCM)
GPIO.setup(button.buttonPin, GPIO.IN)
GPIO.add_event_detect(button.buttonPin, GPIO.FALLING, callback = button.startScaredyBot)
except:
button.scaredyBot.ready = True
def startScaredyBot(button, ev = None):
try:
GPIO.remove_event_detect(button.buttonPin)
button.scaredyBot.ready = True
GPIO.add_event_detect(button.buttonPin, GPIO.FALLING, callback = button.endScaredyBot)
except:
pass
print("Power on!")
def endScaredyBot(button, ev = None):
button.scaredyBot.changeState(_end(button.scaredyBot))
print("Power off!")