-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
executable file
·51 lines (42 loc) · 1.01 KB
/
input.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
#! /usr/bin/python
import RPi.GPIO as GPIO
from time import sleep
from datetime import datetime
from os import system
SNOOZE = 27
SLEEP = 24
buttons = (SNOOZE, SLEEP)
GPIO.setmode(GPIO.BCM)
#GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(buttons, GPIO.IN, pull_up_down=GPIO.PUD_UP)
n = 0
d2 = ""
while True:
try:
c = GPIO.wait_for_edge(buttons, GPIO.FALLING, timeout=2000, bouncetime=200)
except RuntimeError:
sleep(0.5)
print "hest"
continue
except KeyboardInterrupt:
# GPIO.cleanup()
exit(0)
d1 = datetime.now().strftime("%H:%M")
if c == None:
if n > 0:
print "Tune", n
system("sudo -u rn -g rn /home/rn/tune " + str(n))
n = 0
d2 = ""
else:
if d1 != d2:
print d1
d2 = d1
else:
print c
n += 1
print n