-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttp229script.py
51 lines (38 loc) · 1.06 KB
/
ttp229script.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
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
SCL = 27
SDO = 10
touch = 0 # variable for storing pressed pad number
edge_detect = None # variable for detecting press
# GPIO pin modes
GPIO.setup(SCL, GPIO.OUT)
GPIO.setup(SDO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.output(SCL, GPIO.HIGH) # Has to be HIGH
def interrupt():
global touch
touch = 0
sleep(0.000005) # 5us
for i in range(16):
GPIO.output(SCL, GPIO.LOW)
readout = GPIO.input(SDO)
if not readout: # when you press the pad, readout will be 0
touch = i+1
print("{}".format(touch))
sleep(0.00001) # 10us
GPIO.output(SCL, GPIO.HIGH)
sleep(0.00001) # 10us
print("[press ctrl+Z to end the script]")
try: # Main program loop
while True:
edge_detect = GPIO.wait_for_edge(SDO, GPIO.FALLING)
sleep(0.01) # for stability
if edge_detect is not None:
interrupt()
edge_detect = None
# Scavenging work after the end of the program
except KeyboardInterrupt:
print("Script End!")
finally:
GPIO.cleanup()