-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpio.py
57 lines (50 loc) · 1.51 KB
/
gpio.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
import time
import RPi.GPIO as GPIO
from multiprocessing import Queue
from multiprocessing import Process
class MembraneMatrix():
teclas = Queue()
palabraIngresada = ''
MATRIX = [ [1,2,3,'A'],
[4,5,6,'B'],
[7,8,9,'C'],
['*',0,'#','D']]
ROW = [29,31,33,35]
COL = [37,36,38,40]
def __init__(self):
GPIO.setmode(GPIO.BOARD)
for j in range(4):
GPIO.setup(MembraneMatrix.COL[j],GPIO.OUT)
GPIO.output(MembraneMatrix.COL[j],1)
for i in range(4):
GPIO.setup(MembraneMatrix.ROW[i],GPIO.IN,pull_up_down = GPIO.PUD_UP)
self.p = Process(target=self.loop, args=())
self.p.start()
def loop(self):
try:
while(True):
#time.sleep(0.05)
for j in range(4):
GPIO.output(MembraneMatrix.COL[j],0)
for i in range(4):
if GPIO.input(MembraneMatrix.ROW[i]) == 0:
#print(MembraneMatrix.MATRIX[i][j])
MembraneMatrix.teclas.put(MembraneMatrix.MATRIX[i][j])
#print(MembraneMatrix.MATRIX[i][j])
"""
MembraneMatrix.palabraIngresada += MembraneMatrix.MATRIX[i][j]
if MembraneMatrix.MATRIX[i][j] == '*':
MembraneMatrix.teclas.put(MembraneMatrix.palabraIngresada)
print('Ingreso: ',MembraneMatrix.palabraIngresada)
MembraneMatrix.palabraIngresada = ''
"""
while(GPIO.input(MembraneMatrix.ROW[i])==0):
pass
GPIO.output(MembraneMatrix.COL[j],1)
except KeyboardInterrupt:
GPIO.cleanup()
def __del__(self):
GPIO.cleanup()
self.p.join()
if __name__ == '__main__':
miMembrana = MembraneMatrix()