-
Notifications
You must be signed in to change notification settings - Fork 2
/
pingo_parts_record.py
executable file
·73 lines (55 loc) · 1.66 KB
/
pingo_parts_record.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
65
66
67
68
69
70
71
72
73
#!/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.toggle)
self.recording = False
def loop(self):
self.init_led_and_switch()
try:
while(True):
time.sleep(1)
except KeyboardInterrupt:
print("User Cancelled (Ctrl C)")
self.stop_at_exit()
def toggle(self):
print("press")
self.recording = not self.recording
if self.recording:
self.led.blink(times=0, on_delay=0.8, off_delay=0.2) # blink foreever
self.start_recording()
else:
self.led.stop() # stop blinking
self.led.on()
self.stop_recording()
def init_led_and_switch(self):
self.led.on()
self.switch.start()
def start_recording(self):
print("start recording")
def stop_recording(self):
print("stop recording")
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()