This repository was archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeypad.py
More file actions
82 lines (74 loc) · 2.05 KB
/
keypad.py
File metadata and controls
82 lines (74 loc) · 2.05 KB
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
# Group: 24
# Names: Divy, Elio, Kelvin, Matthew
import board
import digitalio
import time
"""
Keypad code for our second Pico board. Reads input from the keypad
and prints the corresponding number to the serial console which is
read by the connected computer (see serial_keypad.py).
"""
# Keypad pin declarations
pRow0 = digitalio.DigitalInOut(board.GP0)
pRow1 = digitalio.DigitalInOut(board.GP1)
pRow2 = digitalio.DigitalInOut(board.GP2)
pRow3 = digitalio.DigitalInOut(board.GP3)
pCol0 = digitalio.DigitalInOut(board.GP4)
pCol1 = digitalio.DigitalInOut(board.GP5)
pCol2 = digitalio.DigitalInOut(board.GP6)
# Keypad pin setup
pRow0.direction = digitalio.Direction.INPUT
pRow1.direction = digitalio.Direction.INPUT
pRow2.direction = digitalio.Direction.INPUT
pRow3.direction = digitalio.Direction.INPUT
pCol0.direction = digitalio.Direction.OUTPUT
pCol1.direction = digitalio.Direction.OUTPUT
pCol2.direction = digitalio.Direction.OUTPUT
# Keypad pull-up setup
pRow0.pull = digitalio.Pull.UP
pRow1.pull = digitalio.Pull.UP
pRow2.pull = digitalio.Pull.UP
pRow3.pull = digitalio.Pull.UP
pCol0.value = True
pCol1.value = True
pCol2.value = True
while True:
# Check 1, 4, 7, *
pCol0.value = False
pCol1.value = True
pCol2.value = True
if pRow0.value == False:
print("1")
elif pRow1.value == False:
print("4")
elif pRow2.value == False:
print("7")
elif pRow3.value == False:
print("*")
time.sleep(0.1)
# Check 2, 5, 8, 0
pCol0.value = True
pCol1.value = False
pCol2.value = True
if pRow0.value == False:
print("2")
elif pRow1.value == False:
print("5")
elif pRow2.value == False:
print("8")
elif pRow3.value == False:
print("0")
time.sleep(0.1)
# Check 3, 6, 9, #
pCol0.value = True
pCol1.value = True
pCol2.value = False
if pRow0.value == False:
print("3")
elif pRow1.value == False:
print("6")
elif pRow2.value == False:
print("9")
elif pRow3.value == False:
print("#")
time.sleep(0.1)