-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPi-9-display7S1DKeypad.py
179 lines (171 loc) · 4.04 KB
/
RPi-9-display7S1DKeypad.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
########################################################################
# Filename : RPi-9-display7S1DKeypad.py
# Description : Controla un Display de 7 Segmentos y 1 digito con un Keypad.
# Author : jcondea
# modification: 2020/10/06
########################################################################
import RPi.GPIO as GPIO
import Keypad #import module Keypad
from time import sleep
ROWS=4
COLS=4
keys = [ '1','2','3','A',
'4','5','6','B',
'7','8','9','C',
'*','0','#','D']
rowsPins=[29,31,33,35]
colsPins=[19,15,13,11]
def print0():
GPIO.output(a,True)
GPIO.output(b,True)
GPIO.output(c,True)
GPIO.output(d,True)
GPIO.output(e,True)
GPIO.output(f,True)
GPIO.output(g,False)
GPIO.output(DP,True)
def print1():
GPIO.output(a,False)
GPIO.output(b,True)
GPIO.output(c,True)
GPIO.output(d,False)
GPIO.output(e,False)
GPIO.output(f,False)
GPIO.output(g,False)
GPIO.output(DP,True)
def print2():
GPIO.output(a,True)
GPIO.output(b,True)
GPIO.output(c,False)
GPIO.output(d,True)
GPIO.output(e,True)
GPIO.output(f,False)
GPIO.output(g,True)
GPIO.output(DP,True)
def print3():
GPIO.output(a,True)
GPIO.output(b,True)
GPIO.output(c,True)
GPIO.output(d,True)
GPIO.output(e,False)
GPIO.output(f,False)
GPIO.output(g,True)
GPIO.output(DP,True)
def print4():
GPIO.output(a,False)
GPIO.output(b,True)
GPIO.output(c,True)
GPIO.output(d,False)
GPIO.output(e,False)
GPIO.output(f,True)
GPIO.output(g,True)
GPIO.output(DP,True)
def print5():
GPIO.output(a,True)
GPIO.output(b,False)
GPIO.output(c,True)
GPIO.output(d,True)
GPIO.output(e,False)
GPIO.output(f,True)
GPIO.output(g,True)
GPIO.output(DP,True)
def print6():
GPIO.output(a,True)
GPIO.output(b,False)
GPIO.output(c,True)
GPIO.output(d,True)
GPIO.output(e,True)
GPIO.output(f,True)
GPIO.output(g,True)
GPIO.output(DP,True)
def print7():
GPIO.output(a,True)
GPIO.output(b,True)
GPIO.output(c,True)
GPIO.output(d,False)
GPIO.output(e,False)
GPIO.output(f,False)
GPIO.output(g,False)
GPIO.output(DP,True)
def print8():
GPIO.output(a,True)
GPIO.output(b,True)
GPIO.output(c,True)
GPIO.output(d,True)
GPIO.output(e,True)
GPIO.output(f,True)
GPIO.output(g,True)
GPIO.output(DP,True)
def print9():
GPIO.output(a,True)
GPIO.output(b,True)
GPIO.output(c,True)
GPIO.output(d,True)
GPIO.output(e,False)
GPIO.output(f,True)
GPIO.output(g,True)
GPIO.output(DP,True)
def printClear():
GPIO.output(a,False)
GPIO.output(b,False)
GPIO.output(c,False)
GPIO.output(d,False)
GPIO.output(e,False)
GPIO.output(f,False)
GPIO.output(g,False)
GPIO.output(DP,False)
GPIO.setmode(GPIO.BOARD)
a=12
b=16
c=18
d=22
e=32
f=36
g=38
DP=40
GPIO.setup(a,GPIO.OUT)
GPIO.setup(b,GPIO.OUT)
GPIO.setup(c,GPIO.OUT)
GPIO.setup(d,GPIO.OUT)
GPIO.setup(e,GPIO.OUT)
GPIO.setup(f,GPIO.OUT)
GPIO.setup(g,GPIO.OUT)
GPIO.setup(DP,GPIO.OUT)
keypad = Keypad.Keypad(keys,rowsPins,colsPins,ROWS,COLS) #create Keypad object
keypad.setDebounceTime(50) #set the debounce time
printClear()
while(1):
key = keypad.getKey() #obtain the state of keys
if(key != keypad.NULL): #if there is key pressed, print its key code.
if key=='0':
print0()
#sleep(.5)
elif key=='1':
print1()
#sleep(.5)
elif key=='2':
print2()
#sleep(.5)
elif key=='3':
print3()
#sleep(.5)
elif key=='4':
print4()
#sleep(.5)
elif key=='5':
print5()
#sleep(.5)
elif key=='6':
print6()
#sleep(.5)
elif key=='7':
print7()
#sleep(.5)
elif key=='8':
print8()
#sleep(.5)
elif key=='9':
print9()
#sleep(.5)
GPIO.clenaup()