-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpingo_parts_toggle.py
executable file
·64 lines (47 loc) · 1.32 KB
/
pingo_parts_toggle.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import atexit
from time import sleep
#import RPi.GPIO as GPIO
import pingo
from pingo.parts.led import Led
from pingo.parts.button import Switch
import time
class App(object):
def __init__(self):
#GPIO.setwarnings(False)
self.board = pingo.detect.get_board()
led_pin = self.board.pins[13]
self.led = Led(led_pin)
self.btn_pin = self.board.pins[7]
self.switch = Switch(self.btn_pin)
self.switch.set_callback_up(self.press)
self.switch.set_callback_down(self.release)
def loop(self):
self.led.off()
self.switch.start()
#self.led.blink(times=0) # blink foreever
try:
while(True):
time.sleep(1)
except KeyboardInterrupt:
print("User Cancelled (Ctrl C)")
self.stop_at_exit()
def press(self):
print("press")
self.toggle()
def release(self):
print("release")
def toggle(self):
self.led.toggle()
def stop_at_exit(self):
self.led.off()
self.switch.stop()
self.led.stop()
self.board.cleanup()
def main():
#atexit.register(GPIO.cleanup)
myapp = App()
myapp.loop()
if __name__ == "__main__":
main()