I bought a 1x4 Matrix Keypad https://www.google.com/url?sa=i&url=https%3A%2F%2Fshopee.com.my%2F-Luminense-1x4-Matrix-Memberane-Switch-Keypad-Numpad-Arduino-Raspberry-Pi-i.63040732.4334990197&psig=AOvVaw3QWnV3IR_JBdNoAzRS-wYA&ust=1635615109861000&source=images&cd=vfe&ved=2ahUKEwjk25Wek_DzAhVCsksFHW_dBtsQr4kDegQIARBc for use in my Raspberry pi 4. The problem I'm facing is I do not know how to program it properly, I did try to make my own code (12 in total) but none of them seem to work properly. Sometimes the code runs but doesn't show the input when I press the button and sometimes it just shows different inputs that's not even the same with the keypad numbering. I need to fix this problem ASAP for my final year project as the due date is near. Anybody know how?
This is the 12th code I made for this keypad
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
button1=16
button2=37
button3=31
button4=29
GPIO.setup(button1,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(button2,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(button3,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(button4,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
while (1):
if GPIO.input(button1)==1:
print("1")
sleep(0.5)
if GPIO.input(button2)==1:
print("2")
sleep(0.5)
if GPIO.input(button3)==1:
print("3")
sleep(0.5)
if GPIO.input(button4)==1:
print("4")
sleep(0.5)
[
I have other codes for this keypad too but this is the one that is close to working I guess. Anyone know how to program one properly?
I use BOARD numbering, white wire is ground (20),button 1 (purple wire) connected at (16),button 2 (blck wire) connected at (37),button 3 (gray wire) connected at (31) and button4 (blue wire) connected at (29).
similar
is kind of useless ... but, follow the tutorials at that link