Is there any example on how to use the pad4pi library from Github to help write a simple door lock python program? (Pressing 1 to unlock solenoid lock, turned on; press 2 to lock, turned off). As shown in the code, this program is kinda tedious that you have to write these codes in order to read inputs by the RPi (turn off row by row in order to check inputs). Does pad4pi reduces that tediousness? If so, how to implement it into the program?
import RPi.GPIO as GPIO import time GPIO.setwarnings(False) #Disable warnings. GPIO.setmode(GPIO.BCM) #Setup BCM GPIO numbering. GPIO.setup(12, GPIO.OUT) #Set GPIO12 as output. COL = [16,20,21] #BCM Numbering for Columns. GPIO.setup(6,GPIO.OUT) #Set Row 1 as output. GPIO.output(6,1) #Set Row 1 high. for j in range(2): GPIO.setup(COL[j], GPIO.IN, pull_up_down = GPIO.PUD_UP) #Defining input GPIOs with pull-up resistor for Col 1 and 2. #--------Main program-------- try: while(True): #Never-ending loop unless ctrl+c is pressed (which goes to KeyboardInterrupt). GPIO.output(6,0) #Set ROW 1 low first, to check inputs (i.e. which button is pressed). if GPIO.input(COL) == 0: #When '1' is pressed, GPIO.output(12, True) #unlock. (i.e. GPIO12 goes high) while GPIO.input(COL) == 1: #If '2' is not pressed yet, GPIO.output(12, True) #stays unlocked. if GPIO.input(COL) == 0: #If '2' is pressed, GPIO.output(12, False) #lock. else: GPIO.output(12, False) #If '1' is not pressed, then it stays locked. GPIO.output(6,1) #Set all Row 1 back to high. except KeyboardInterrupt: #When CTRL+C is pressed, GPIO.cleanup() #Resetting GPIO to defaults, then ends the program.