Rasp Pi2 help, 4x4 keypad problems - Raspberry Pi Forums
like many on forum i'm new rasp pi's / coding , i'm having trouble. i've been working on project lately in i'm trying hookup 4x4 keypad pi. i'm attempting print out pins active once press 1 of buttons. know keypad has 4 rows , 4 collums , figure out pins buttons. sake of project want able plug in random keypad don't know configuration of , still read out pins being used once press button.
don't have experience pi's or coding i've came far. please excuse how bad is, i'm sure looks awful , redundant knows looking at. i'm trying cycle 1 output pin rest being input. once reach max number of pins keypad being used (which 8 in case) loop it.
problem i'm having when press button, 1 connected pin 1 , 8. prints out 1 , 8 prints out 2 , 8. not prints them out fast.
appreciated
don't have experience pi's or coding i've came far. please excuse how bad is, i'm sure looks awful , redundant knows looking at. i'm trying cycle 1 output pin rest being input. once reach max number of pins keypad being used (which 8 in case) loop it.
code: select all
import rpi.gpio gpio, time gpio.setmode(gpio.bcm) gpio.setwarnings(false) #step 1 of 8 def main_1(channel): gpio.setmode(gpio.bcm) pin_1 = 4 #output pin_2 = 17 pin_3 = 27 pin_4 = 22 pin_5 = 5 pin_6 = 6 pin_7 = 13 pin_8 = 26 gpio.setup(pin_1, gpio.out,true) gpio.setup(pin_2, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_3, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_4, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_5, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_6, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_7, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_8, gpio.in, pull_up_down=gpio.pud_up) #pin_1 output def prnt_pin_2(channel): print('pin 1 , 2') def prnt_pin_3(channel): print('pin 1 , 3') def prnt_pin_4(channel): print('pin 1 , 4') def prnt_pin_5(channel): print('pin 1 , 5') def prnt_pin_6(channel): print('pin 1 , 6') def prnt_pin_7(channel): print('pin 1 , 7') def prnt_pin_8(channel): print('pin 1 , 8') #pin_1 output gpio.add_event_detect(pin_2, gpio.both, callback=prnt_2, bouncetime=500) gpio.add_event_detect(pin_3, gpio.both, callback=prnt_3, bouncetime=500) gpio.add_event_detect(pin_4, gpio.both, callback=prnt_4, bouncetime=500) gpio.add_event_detect(pin_5, gpio.both, callback=prnt_5, bouncetime=500) gpio.add_event_detect(pin_6, gpio.both, callback=prnt_6, bouncetime=500) gpio.add_event_detect(pin_7, gpio.both, callback=prnt_7, bouncetime=500) gpio.add_event_detect(pin_8, gpio.both, callback=prnt_8, bouncetime=500) time.sleep(1) gpio.cleanup() main_2() #step 2 of 8 def main_2(channel): gpio.setmode(gpio.bcm) pin_1 = 4 pin_2 = 17 #output pin_3 = 27 pin_4 = 22 pin_5 = 5 pin_6 = 6 pin_7 = 13 pin_8 = 26 gpio.setup(pin_1, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_2, gpio.out,true) gpio.setup(pin_3, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_4, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_5, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_6, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_7, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(pin_8, gpio.in, pull_up_down=gpio.pud_up) #pin_2 output def prnt_pin_3(channel): print('pin 2 , 3') def prnt_pin_4(channel): print('pin 2 , 4') def prnt_pin_5(channel): print('pin 2 , 5') def prnt_pin_6(channel): print('pin 2 , 6') def prnt_pin_7(channel): print('pin 2 , 7') def prnt_pin_8(channel): print('pin 2 , 8') #pin_2 output gpio.add_event_detect(pin_3, gpio.both, callback=prnt_3, bouncetime=500) gpio.add_event_detect(pin_4, gpio.both, callback=prnt_4, bouncetime=500) gpio.add_event_detect(pin_5, gpio.both, callback=prnt_5, bouncetime=500) gpio.add_event_detect(pin_6, gpio.both, callback=prnt_6, bouncetime=500) gpio.add_event_detect(pin_7, gpio.both, callback=prnt_7, bouncetime=500) gpio.add_event_detect(pin_8, gpio.both, callback=prnt_8, bouncetime=500) time.sleep(1) gpio.cleanup() main_3() #ect...
appreciated
raspberrypi
Comments
Post a Comment