Jump to content

armbian orange pi: read matrix keypad 4x4 in python


Recommended Posts

i used  this python script to read matrix 4x4 keypad data to raspberry pi 

 

import RPi.GPIO as GPIO  #raspberry pi
import time

# these GPIO pins are connected to the keypad  RPI
L1 = 21
L2 = 23
L3 = 27
L4 = 29

C1 = 31
C2 = 33  
C3 = 35
C4 = 37

# Initialize the GPIO pins
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

GPIO.setup(L1, GPIO.OUT)
GPIO.setup(L2, GPIO.OUT)
GPIO.setup(L3, GPIO.OUT)
GPIO.setup(L4, GPIO.OUT)

# Make sure to configure the input pins to use the internal pull-down resistors
GPIO.setup(C1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# It sends out a single pulse to one of the rows of the keypad
# and then checks each column for changes
# If it detects a change, the user pressed the button that connects the given line
# to the detected column

def readLine(line, characters):
    GPIO.output(line, GPIO.HIGH)
    if(GPIO.input(C1) == 1):
        print(characters[0])
    if(GPIO.input(C2) == 1):
        print(characters[1])

    if(GPIO.input(C3) == 1):
        print(characters[2])

    if(GPIO.input(C4) == 1):
        print(characters[3])

    GPIO.output(line, GPIO.LOW)

try:
    while True:
        # call the readLine function for each row of the keypad
        readLine(L1, ["1","2","3","e"])
        readLine(L2, ["4","5","6","r"])
        readLine(L3, ["7","8","9","t"])
        readLine(L4, ["q","0","w","y"])
        time.sleep(0.2)
except KeyboardInterrupt:
    print("\nApplication stopped!")

 

 

How can i create similar script for orange pi in armbian (in my case orange pi pc plus)?

it can by python or other language  doesnt matter

Edited by ari1234
Link to comment
Share on other sites

  • ari1234 changed the title to armbian orange pi: read matrix keypad 4x4 in python

Armbian Linux community supported weekly builds download

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...