Nov-05-2017, 05:01 AM
Not sure how to properly differentiate code between normal talk on here. New to the site, please bear with me. I do appreciate tips and advice if given.I am new to coding, currently taking a programming class. This is a personal project i thought would be fun.
I am working on a security program using a 4x4 matrix keypad w/RPi3. The keypad is not a membrane style, it is more like the old landline phones with white plastic buttons.
From what I can gather, based on what I have learned in class, i will also need an if/else loop or two.
Code:
import RPi.GPIO
GPIO.setmode(GPIO.BCM)
#Set Keypad Layout
Keypad = [
[1, 2, 3, "A"],
[4, 5, 6, "B"],
[7, 8, 9, "C"],
[0, "F", "E", "D"]
]
#Keypad -> GPIO Pin Out
#BCM Numbering
COL_PINS = [4, 17, 22, 27]
ROW_PINS = [18, 25, 5, 6]
#example keypad entered code
#CODE = A12345
factory = rpi_gpio.KeypadFactory()
# Try factory.create_4_by_3_keypad
# and factory.create_4_by_4_keypad for reasonable defaults
keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
def printKey(key):
print(key)
# printKey will be called each time a keypad button is pressed
keypad.registerKeyPressHandler(printKey)
Code End
I am working on a security program using a 4x4 matrix keypad w/RPi3. The keypad is not a membrane style, it is more like the old landline phones with white plastic buttons.
From what I can gather, based on what I have learned in class, i will also need an if/else loop or two.
Code:
import RPi.GPIO
GPIO.setmode(GPIO.BCM)
#Set Keypad Layout
Keypad = [
[1, 2, 3, "A"],
[4, 5, 6, "B"],
[7, 8, 9, "C"],
[0, "F", "E", "D"]
]
#Keypad -> GPIO Pin Out
#BCM Numbering
COL_PINS = [4, 17, 22, 27]
ROW_PINS = [18, 25, 5, 6]
#example keypad entered code
#CODE = A12345
factory = rpi_gpio.KeypadFactory()
# Try factory.create_4_by_3_keypad
# and factory.create_4_by_4_keypad for reasonable defaults
keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
def printKey(key):
print(key)
# printKey will be called each time a keypad button is pressed
keypad.registerKeyPressHandler(printKey)
Code End