def controlPanel(): # Keypad configuration factory = rpi_gpio.KeypadFactory() keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) keypad.registerKeyPressHandler(keyPress) # Set the LCD to the default display lcd.updateLCDScreen("Passcode:[ ]", 1) lcd.updateLCDScreen("Clear:* Submit:#", 4) previousAlarmStatus = "" global backlightTimer while True: alarmStatus = securitySystemRequest("alarm_status.php") if (alarmStatus != previousAlarmStatus): previousAlarmStatus = alarmStatus lcd.updateLCDScreen(" ", 3) lcd.updateLCDScreen("Alarm: " + str(alarmStatus), 3) backlightTimer = backlightTimerDuration time.sleep(1) print("Backlight Timer: " + str(backlightTimer))
def __init__(self, p1, p2, p3, p4, p5, p6, p7, p8): self.screen = led.matrix(cascaded=1) self.screen.clear() self.SIZE_LED = 8 self.SNAKE_SIZE = 1 self.STARTX = 0 self.STARTY = 0 self.PRZERWA = 0.4 self.kierunek = "prawo" self.x = self.STARTX self.y = self.STARTY self.pozycje = [] self.punkt = str(randint(0, self.SIZE_LED - 1)) + str( randint(0, self.SIZE_LED - 1)) self.poprzedni = 0 self.miganie = 0 self.score = 0 self.KEYPAD = [["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"], ["*", "0", "#", "D"]] self.ROW_PINS = [p1, p2, p3, p4] self.COL_PINS = [p5, p6, p7, p8] self.factory = rpi_gpio.KeypadFactory() self.keypad = self.factory.create_keypad(keypad=self.KEYPAD, row_pins=self.ROW_PINS, col_pins=self.COL_PINS) self.keypad.registerKeyPressHandler(self.processKey)
class KeyPad: # Setup Keypad KEYPAD = [["3", "2", "1", "A"], ["6", "5", "4", "B"], ["9", "8", "7", "C"], ["0", ".", "X", "D"]] # same as calling: factory.create_4_by_4_keypad, still we put here fyi: ROW_PINS = [ 16, 20, 21, 5 ] # BCM numbering; Board numbering is: 7,8,10,11 (see pinout.xyz/) COL_PINS = [ 6, 13, 19, 26 ] # BCM numbering; Board numbering is: 12,13,15,16 (see pinout.xyz/) factory = rpi_gpio.KeypadFactory() # Try keypad = factory.create_4_by_3_keypad() or # Try keypad = factory.create_4_by_4_keypad() #for reasonable defaults # or define your own: keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) def printkey(key): print(key) keypad.registerKeyPressHandler(printkey) try: while (True): time.sleep(0.2) except: keypad.cleanup()
def __init__(self): """Keypad Constructor""" # Setup Keypad Layout KEYPAD = [ ["1","2","3","A"], ["4","5","6","B"], ["7","8","9","C"], ["*","0","#","D"] ] #Pi BCM Pins used ROW_PINS = [2, 3, 4, 17] COL_PINS = [27, 22, 10, 9] self.lastKeyPressed = "" #Keypad initialization code self.factory = rpi_gpio.KeypadFactory() self.keypad = self.factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) #keyPressed will be called each time a keypad button is pressed self.keypad.registerKeyPressHandler(self.keyPressed)
def Keypad_Interrupt_Driver(): #Keypad wiring and code setup: http://codelectron.com/how-to-interface-keypad-with-raspberry-pi/ KEYPAD = [ ["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["*", "0", "#"], ] ROW_PINS = [2, 3, 4, 12] #Defines Row pins COL_PINS = [17, 27, 22] #Defines Column Pins factory = rpi_gpio.KeypadFactory() #Defines keypad Factory object #Initializes keypad and its pins keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) #Creates interrupt and calles "processKey" if interrupt keypad.registerKeyPressHandler(processKey) while True: time.sleep(1) keypad.cleanup() #Cleans up object
def init(self): gpio.cleanup() print("Hi") self.zeile = [1, 7, 8, 16] self.spalte = [24, 6, 15, 13] # Keypad self.matrix = [["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"], ["*", "0", "#", "D"]] self.factory = rpi_gpio.KeypadFactory() self.keypad = factory.create_keypad(keypad=self.matrix, row_pins=self.zeile, col_pins=self.spalte) self.keypad.registerKeyPressHandler(printKey) self.password = ["4", "0", "2", "8"] gpio.setmode(gpio.BCM) gpio.setwarnings(False) for j in range(4): gpio.setup(self.spalte[j], gpio.OUT) gpio.output(self.spalte[j], 1) gpio.setup(self.zeile[j], gpio.IN, pull_up_down=gpio.PUD_UP) print("Hi")
def __init__(self, timeout=5): self.timeout = timeout self.input = "" self.accepting = False self.last_time = 0 factory = rpi_gpio.KeypadFactory() self.keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) # printKey will be called each time a keypad button is pressed self.keypad.registerKeyPressHandler(self.key_pressed)
def __init__(self, keys=None, row_pins=None, col_pins=None): # Setup Keypad if keys is None: self.KEYS = [[1, 2, 3, "A"], [4, 5, 6, "B"], [7, 8, 9, "C"], ["*", 0, "#", "D"]] if row_pins is None: self.row_pins = [5, 6, 13, 19] # BCM numbering if col_pins is None: self.col_pins = [26, 16, 20, 21] # BCM numbering factory = rpi_gpio.KeypadFactory() self.keypad = factory.create_keypad(keypad=self.KEYS, row_pins=self.row_pins, col_pins=self.col_pins)
def setup(): global EffectsServer print("> Setup") config = configparser.ConfigParser() config.read('config.ini') EffectsServer = config['DEFAULT']['EffectsServer'] factory = rpi_gpio.KeypadFactory() keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) keypad.registerKeyPressHandler(process_key) return keypad
def controlPanel(): factory = rpi_gpio.KeypadFactory() keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) keypad.registerKeyPressHandler(print_key) # Variables global alarmArmed while True: if (alarmArmed): userResponse = raw_input("Disarm the system? (y/n): ") if (userResponse == "y"): alarmArmed = False else: userResponse = raw_input("Arm the system? (y/n): ") if (userResponse == "y"): alarmArmed = True
def __init__(self): self.layout = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ["*", 0, "#"] ] self.ROW_PINS = [26, 19, 13, 6] # BCM numbering self.COL_PINS = [21, 20, 16] # BCM numbering factory = rpi_gpio.KeypadFactory() self.kp = factory.create_keypad(keypad=self.layout, row_pins=self.ROW_PINS, col_pins=self.COL_PINS) # printKey will be called each time a keypad button is pressed self.kp.registerKeyPressHandler(self.log_key) self.output = ''
def setup(): global units global ready global ser ser = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=2) KEYPAD = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], ["*", "0", "#"]] ROW_PINS = [21, 20, 16, 12] COL_PINS = [26, 19, 13] factory = rpi_gpio.KeypadFactory() keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) keypad.registerKeyPressHandler(handleKeyPress) GPIO.setup(4, GPIO.OUT) GPIO.output(4, GPIO.LOW) time.sleep(4) GPIO.output(4, GPIO.HIGH) time.sleep(15) with open("config.json", "r") as config: units = json.load(config) registered = "" ser.write(b"AT+CREG?\r\n") registered = ser.read(50).decode(encoding="utf-8") print(registered) while "OK" not in registered: registered = "" GPIO.output(4, GPIO.LOW) time.sleep(4) GPIO.output(4, GPIO.HIGH) time.sleep(15) ser.write(b"AT+CREG?\r\n") registered = ser.read(50).decode(encoding="utf-8") print(registered) ready = True
def keypad(): """ Initializes keypad and sets up configuration and listener """ KEYPAD = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ["*", 0, "#"]] ROW_PINS = [17, 27, 22, 24] # BCM numbering COL_PINS = [4, 18, 23] # BCM numbering 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) print("Keypad Intialized... Enter keys") keypad.registerKeyPressHandler(key_pressed)
class Keypad: should_show = False is_ok_clicked = False is_back_clicked = False is_delete_clicked = False current_str = "" last_char = "" 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 __init__(self): self.keypad.registerKeyPressHandler(self.printKey) def resetKeypad(self): self.is_back_clicked = False self.is_delete_clicked = False self.is_ok_clicked = False def printKey(self, key): self.last_char = key if key == 'A': self.is_ok_clicked = True elif key == 'B': self.is_back_clicked = True if len(self.current_str) != 0: self.current_str = self.current_str[:-1] elif key == 'C': self.is_delete_clicked = True else: self.is_ok_clicked = False self.is_back_clicked = False self.is_delete_clicked = False self.current_str += key
def main(self): try: init() print(Back.WHITE + 'Initializing SmartTwo Controller.' + Style.RESET_ALL) #WebAPI threading._start_new_thread(flaskThread, ()) #Devices ##Lights lights = Lights.Lights() lights.start() ##TV tv = TV.TV() tv.start() print(Back.WHITE + 'Initializing Keypad.' + Style.RESET_ALL) ##Keypad KEYPAD = [[1, 2, 3, "A"], [4, 5, 6, "B"], [7, 8, 9, "C"], ["*", 0, "#", "D"]] factory = rpi_gpio.KeypadFactory() ROW_PINS = [2, 3, 4, 17] # BCM numbering COL_PINS = [22, 27, 10, 9] # BCM numbering self.keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) self.keypad.registerKeyPressHandler(self.key_pressed) signal('code_0').connect(self.lock_console) print(Back.GREEN + 'SmartTwo Controller Started' + Style.RESET_ALL) while True: time.sleep(1) except KeyboardInterrupt: print(Back.RED + "Stopping SmartTwo Controller" + Style.RESET_ALL) signal('SYSTEM_stopping').send(self) finally: self.keypad.cleanup()
def setup_keypad(): if not config.getboolean('keypad', 'enable'): print("keypad disabled") return print("setting up keypad") keypad_values['keypressed'] = None keypad_values['date'] = (datetime.datetime.now() - datetime.timedelta(days=-1)) KEYPAD = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ["*", 0, "#"]] ROW_PINS = list() row_raw = config.get('keypad', 'row_pin').split(",") for i in range(len(row_raw)): ROW_PINS.append(int(row_raw[i])) print(ROW_PINS) COL_PINS = list() col_raw = config.get('keypad', 'col_pin').split(",") for i in range(len(col_raw)): COL_PINS.append(int(col_raw[i])) print(COL_PINS) #ROW_PINS = [4, 14, 15, 17] # BCM numbering #COL_PINS = [18, 27, 22] # BCM numbering 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, key_delay=config.getint( 'keypad', 'key_delay')) # printKey will be called each time a keypad button is pressed keypad.registerKeyPressHandler(handleKeyPad) print("setup keypad complete") return keypad
def __init__(self): self.dot = Dot() self.keypad = Keypad() self.motor = Motor() self.face_recog_op = Face_Recog_Op(self.keypad) self.lock_switch = 19 self.change_pass_switch = 13 self.close_switch = 5 self.add_face_switch = 6 self.Locked = True self.Door_closed = True self.passwd = [1, 2, 3, 4, 5] self.kp = rpi_gpio.KeypadFactory().create_keypad( keypad=self.keypad.KEYPAD, row_pins=self.keypad.ROW, col_pins=self.keypad.COLUMN) GPIO.setup(self.lock_switch, GPIO.IN, GPIO.PUD_UP) GPIO.setup(self.change_pass_switch, GPIO.IN, GPIO.PUD_UP) GPIO.setup(self.close_switch, GPIO.IN, GPIO.PUD_UP) GPIO.setup(self.add_face_switch, GPIO.IN, GPIO.PUD_UP) GPIO.add_event_detect(self.lock_switch, GPIO.RISING, callback=self.door_op, bouncetime=2000) GPIO.add_event_detect(self.change_pass_switch, GPIO.RISING, callback=self.change_passwd_op, bouncetime=10000) GPIO.add_event_detect(self.close_switch, GPIO.RISING, callback=self.close_after_3s, bouncetime=5000) GPIO.add_event_detect(self.add_face_switch, GPIO.RISING, callback=self.face_add_and_train, bouncetime=50000) self.kp.registerKeyPressHandler(self.key_pressed)
def __init__(self, p1, p2, p3, p4, p5, p6, p7, p8): self.KEYPAD = [ ["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"], ["*", "0", "#", "D"] ] self.ROW_PINS = [p1, p2, p3, p4] self.COL_PINS = [p5, p6, p7, p8] self.x = randint(0,self.SIZE_LED-1) self.y = randint(0,self.SIZE_LED-1) self.tablica =[] self.screen = led.matrix(cascaded=1) self.screen.pixel(self.x, self.y, True, redraw=True) self.factory = rpi_gpio.KeypadFactory() self.keypad = self.factory.create_keypad(keypad=self.KEYPAD, row_pins=self.ROW_PINS, col_pins=self.COL_PINS) self.keypad.registerKeyPressHandler(self.processKey) while True: self.screen.pixel(self.x, self.y, True, redraw=True) time.sleep(0.5) self.screen.pixel(self.x, self.y, False, redraw=True) time.sleep(0.5)
def __init__(self, mainWindow, mainWidth, mainHeight): frame_main = Frame(mainWindow, width=mainWidth, height=mainHeight) frame_main.grid(row=0, column=0) lblTitle = Label(mainWindow, text="Ingrese su número de cédula", font=(None, 45)) lblTitle.place(x=self.posElement(50, mainWidth), y=self.posElement(20, mainHeight), anchor="center") #Validación de solo números #reg = mainWindow.register(val.onlyDigits) #reg = mainWindow.register() #txtCedula = Entry(mainWindow, font="Helvetica 60 bold", width=15, justify="center", validate="all", validatecommand=(reg, '%P')) txtCedula = Entry(mainWindow, font="Helvetica 120 bold", width=15, justify="center") txtCedula.place(x=self.posElement(50, mainWidth), y=self.posElement(50, mainHeight), anchor="center") txtCedula.focus() lblTitle2 = Label(mainWindow, text="Presione Click en 'ENTER' para continuar.", font=(None, 45)) lblTitle2.place(x=self.posElement(50, mainWidth), y=self.posElement(80, mainHeight), anchor="center") # Setup Keypad KEYPAD = [["3", "2", "1", "A"], ["6", "5", "4", "B"], ["9", "8", "7", "C"], ["0", ".", "X", "D"]] # same as calling: factory.create_4_by_4_keypad, still we put here fyi: ROW_PINS = [ 16, 20, 21, 5 ] # BCM numbering; Board numbering is: 7,8,10,11 (see pinout.xyz/) COL_PINS = [ 6, 13, 19, 26 ] # BCM numbering; Board numbering is: 12,13,15,16 (see pinout.xyz/) factory = rpi_gpio.KeypadFactory() # Try keypad = factory.create_4_by_3_keypad() or # Try keypad = factory.create_4_by_4_keypad() #for reasonable defaults # or define your own: keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) def printkey(key): if self.estado == 0: if self.maxlong < 10: if (key == '1' or key == '2' or key == '3' or key == '4' or key == '5' or key == '6' or key == '7' or key == '8' or key == '9' or key == '0'): txtCedula.insert(END, key) elif key == 'D': #FIXME Validar número de cédula self.estado = 1 frame_menu.MenuForm(mainWindow, mainWidth, mainHeight) mainWindow.update() print "show" if key == 'X' or key == 'A': txtCedula.delete(0, 'end') self.maxlong = len(txtCedula.get()) elif self.estado == 1: if (key == '1'): self.print_certificado_notas() elif key == '2': self.print_certificado_matricula() print(key) keypad.registerKeyPressHandler(printkey)
import time #import delay time from pad4pi import rpi_gpio #connect to keypad import RPi.GPIO as GPIO #connect to RPi GPIO.setwarnings(False) #disable warnings #define Pins KEYPAD=[ [1,2,3,"A"] [4,5,6,"B"] [7,8,9,"C"] ["*",0,"#","D"] ] ROW_PINS=[21,20,16,12] COL_PINS=[26,19,13,6] factory=rpi_gpio.KeypadFactory() #connect Pins to default library keypad=factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) def printKey(key): print (key) #main loop while True: #unlimited loop keypad.registerKeyPressHandler(printKey) #get key time.sleep(.5) #delay 500ms keypad.clearKeyPressHandlers() #clear key
def main(): print("Getting to the task at hand...") #Setup GPIO.setmode(11) GPIO.setwarnings(False) GPIO.setup(21,GPIO.OUT) global buffer global flagA global flagB global flagC global OTC_med_list_input global quant_available flagA = 0 flagB = 0 flagC = 0 buffer = "" OTC_med_list_input = [] qr_path = '/home/pi/Desktop/picampics/myqr.png' # LCD pin setup # Define GPIO to LCD mapping LCD_RS = 5 LCD_E = 6 LCD_D4 = 7 LCD_D5 = 8 LCD_D6 = 9 LCD_D7 = 10 # Define some device constants LCD_WIDTH = 16 # Maximum characters per line LCD_CHR = True LCD_CMD = False LCD_LINE_1 = 0x81 # LCD RAM address for the 1st line LCD_LINE_2 = 0xC1 # LCD RAM address for the 2nd line # Timing constants E_PULSE = 0.0005 E_DELAY = 0.0005 GPIO.setup(LCD_E, GPIO.OUT) # E GPIO.setup(LCD_RS, GPIO.OUT) # RS GPIO.setup(LCD_D4, GPIO.OUT) # DB4 GPIO.setup(LCD_D5, GPIO.OUT) # DB5 GPIO.setup(LCD_D6, GPIO.OUT) # DB6 GPIO.setup(LCD_D7, GPIO.OUT) # DB7 lcd_init() """ lcd_rs = 12 lcd_en = 25 lcd_d4 = 21 lcd_d5 = 16 lcd_d6 = 20 lcd_d7 = 26 lcd_backlight = 2 # Define LCD column and row size for 16x2 LCD. lcd_columns = 16 lcd_rows = 2 lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight) lcd.clear() """ #camera = picamera.PiCamera() print("Setup complete.") #constants # String from qr, required in this code coz kamera nahi hai string = 'crocin,2,paracetamol,3,vix,15' #cost of meds cost_list = {'crocin': 200, 'paracetamol': 300, 'vix': 10, 'abc':0,'xyz': 50} #quant in machine initially quant_available = {'crocin': 10, 'paracetamol': 10, 'vix': 10, 'abc': 10,'xyz':10 } #motor mapping dict motor_map = {'crocin':27, 'paracetamol':2, 'vix':3, 'abc':4, 'xyz':22 } #print("Values taken into account") # same as calling: factory.create_4_by_4_keypad, still we put here fyi: ROW_PINS = [11, 12, 13, 14]# BCM numbering COL_PINS = [15, 16, 17, 18] # BCM numbering 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) #keypad.cleanup() ''' Phase 1 1) lcd_display ('plz press the button ) 2) user presses the button 3) camera activates and takes pic ''' """ lcd.clear() lcd.message('Press OK to proceed\nShow QR Code to cam') """ #Waiting for button to be pressed keypad.registerKeyPressHandler(printKey) """ Keypad flow: Default value of flag is 0 Flag is set to 1 to break out of infinite loop when A is pressed to switch camera on Flag remains 1 thereafter Flag is set to Flag is set to 2 when A is pressed to confirm input of mobile number """ """ try: while(True): if flagA == 1: break else: time.sleep(0.2) except: keypad.cleanup() """ print("About to be active...") try: while(True): print("Active as hell") flagA = 1 # Flag for OTC mode GPIO.setup(LCD_RS, GPIO.OUT) # RS lcd_display(0x01,LCD_CMD) print("Seems to break here") lcd_string("Welcome to MedSpenser!",LCD_LINE_1) print("Shit") lcd_string("Show QR code to cam",LCD_LINE_2) print("Show QR code to cam") #Capturing image print("Ready to capture QR code") os.system('raspistill -o /home/pi/Desktop/picampics/myqr.png') lcd_display(0x01,LCD_CMD) lcd_string("Press A to get OTC med",LCD_LINE_1) lcd_string("Or show QR code to cam",LCD_LINE_2) #saving string time.sleep(0.1) string = decode_qr(qr_path) #print("String decoded.") print("QR extracted.") print("Extracted text: %s" % string) ''' Phase 2 1)decode qr 2)create output med list 3)calculate price ''' if string == "NULL": print("There seems to be no QR code in front of the camera. Activating camera...") lcd_display(0x01,LCD_CMD) lcd_string("I'm waiting to be used!",LCD_LINE_1) lcd_string("Please show valid QR code", LCD_LINE_2) time.sleep(3) else: print("Continuing ahead...") break except: keypad.cleanup() flagA = 0 ''' Phase 3 1) lcd displays price 2) user pays SOMEHOW 3) motors go round round round ''' #Creating input dictionary med_list_input = decode_string(string) #Creating final dictionary final_med_list = meds_output(med_list_input,quant_available) #Updating quantity available quant_available = update_quant(med_list_input,quant_available) #Calculating price price = price(final_med_list,cost_list) print("Price calculated.") print (price) time.sleep(1) dispenseAndPay(price,final_med_list,motor_map) print (med_list_input) print (quant_available)
if track_keys.state != "Reset Password": track_keys.state = "KeyPressed" track_keys.pressed += key # initialize static variables. track_keys.pressed = "" track_keys.store = False track_keys.state = "Locked" # Setup Keypad keypad = rpi_gpio.KeypadFactory().create_keypad( keypad=[["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"], ["*", "0", "#", "D"]], row_pins=[ 4, 14, 15, 17 ], # BCM numbering; Board numbering is: 7,8,10,11 (see pinout.xyz/) col_pins=[ 18, 27, 22, 23 ] # BCM numbering; Board numbering is: 12,13,15,16 (see pinout.xyz/) ) # track_keys will be called each time a keypad button is pressed keypad.registerKeyPressHandler(track_keys) def pushbutton_callback(channel): print("Enter a password followed by the pound sign (#)") track_keys.store = True track_keys.pressed = "" track_keys.state = "Reset Password"
pin_rs=7, pin_e=8, #pin_reset and pin_enable pins_data=[25,24,23,18], #pin_data numbering_mode=GPIO.BCM) #BCM mode KEYPAD=[ [1,2,3,"A"] [4,5,6,"B"] [7,8,9,"C"] ["*",0,"#","D"] ] ROW_PINS=[21,20,16,12] COL_PINS=[26,19,13,6] factory=rpi_gpio.KeypadFactory() #set deafult Keypad keypad=factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) time.sleep(1) #delay at beginning lcd.cursor_pos=(0,0) with cleared(lcd): lcd.write_string(u'') #clear LCD at beginnig lcd.cursor_pos=(1,0) with cleared(lcd): lcd.write_string(u'') lcd.cursor_pos=(0,0) #define start point column=0 row=0 lcd.write_string('Raspberry Pi') #sample text time.sleep(2) #delay time
def main(pipe=1): global triggers_list global phones_list global HANDSET_PIN HANDSET_PIN = 26 triggers_list = [] phones_list = [] TONE_PIN_1 = 25 TONE_PIN_2 = 26 HANDSET_PIN = 19 HUNG_UP_LOGIC = 0 unlock_code = [2, 6, 0, 7] global phone_on_hook phone_on_hook = True global DTMF_Tone1 global DTMF_Tone2 DTMF_Tone1 = [941, 697, 697, 697, 770, 770, 770, 852, 852, 852, 941, 941] DTMF_Tone2 = [ 1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1477 ] def playDtmfTones(key): global DTMF_Tone1 global DTMF_Tone2 stopTones() try: int_key = int(key) if int_key >= 0 and int_key <= 9: tone1.ChangeFrequency(DTMF_Tone1[key]) tone2.ChangeFrequency(DTMF_Tone2[key]) tone1.start(50) tone2.start(50) except ValueError: if key == '*': tone1.ChangeFrequency(DTMF_Tone1[10]) tone2.ChangeFrequency(DTMF_Tone2[10]) tone1.start(50) tone2.start(50) elif key == '#': tone1.ChangeFrequency(DTMF_Tone1[11]) tone2.ChangeFrequency(DTMF_Tone2[11]) tone1.start(50) tone2.start(50) def stopTones(): tone1.stop() tone2.stop() def playDialTone(): tone1.ChangeFrequency(350) tone2.ChangeFrequency(440) tone1.start(50) tone2.start(50) def cleanup(): global keypad keypad.cleanup() def printKeyPressed(key): global keypad try: int(key) print(str(key)) print(keypad.enteredCode) except ValueError: print(keypad.enteredCode) print(key) def keypadAction(key): global keypad if key == -1: #Button was realeased stopTones() else: playDtmfTones(key) print(str(key)) print(keypad.enteredCode) def checkHandset(): global keypad global phone_on_hook if (GPIO.input(HANDSET_PIN) == HUNG_UP_LOGIC): keypad.clearEnteredCode print("Phone was hung up") phone_on_hook = True else: playDialTone() print("Phone was picked up") phone_on_hook = False def load_phone_settings(): global triggers_list global phones_list triggers_list = [] phones_list = [] with open('phone_settings.json') as f: loaded_data = json.load(f) temp_list = [] for i in range(len(loaded_data['phone settings'])): temp_list = loaded_data['phone settings'][i] phone_temp = telephone(temp_list['number'], temp_list['name'], temp_list['ringer'], temp_list['dial tone'], temp_list['ringer message'], temp_list['wrong number']) phones_list.append(phone_temp) for i in range(len(loaded_data['triggers'])): temp_list = loaded_data['triggers'][i] trigger_temp = trigger( temp_list['number'], temp_list['name'], temp_list['unlock code'], temp_list['is active'], temp_list['trigger message'], temp_list['relay mode'], temp_list['relay active time'], temp_list['relay active'], temp_list['relay message timing'], temp_list['message file']) triggers_list.append(trigger_temp) del temp_list def check_handset(): ''' global phone_on_hook global HANDSET_PIN if (GPIO.input(HANDSET_PIN) == OFF_THE_HOOK): phone_on_hook = True else: phone_on_hook = False ''' pass #GPIO.add_event_detect(HANDSET_PIN, GPIO.BOTH, callback=check_handset, bouncetime=30) #Add interrupt for handset load_phone_settings() print(str(pipe)) print(phones_list[0].returnPhoneSettingsList()) print(triggers_list[0].returnTriggerValuesList()) try: factory = rpi_gpio.KeypadFactory() keypad = factory.create_4_by_3_keypad( ) # makes assumptions about keypad layout and GPIO pin numbers keypad.registerKeyPressHandler(keypadAction) GPIO.setup(HANDSET_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(TONE_PIN_1, GPIO.OUT) GPIO.setup(TONE_PIN_2, GPIO.OUT) GPIO.add_event_detect(HANDSET_PIN, GPIO.BOTH, callback=checkHandset, bouncetime=40) tone1 = GPIO.PWM(TONE_PIN_1, 50) tone2 = GPIO.PWM(TONE_PIN_2, 50) #pygame.mixer.init() print("Enter your passcode (hint: {0})".format(unlock_code)) while True: time.sleep(.001) if (keypad.released): keypad.released = False if (keypad.enteredCode == unlock_code): time.sleep(.05) print("You Win the game!!!") keypad.clearEnteredCode() except KeyboardInterrupt: print("Goodbye") finally: cleanup()
FLAG_START_IMPACTO = None FLAG_START_MELODIA = None FLAG_JUEGO_TERMINADO = None FLAG_MENU = None FLAG_DIFI = None difi = None KEYPAD = [ # declaracion de la matriz del teclado ["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"], ["*", "0", "#", "D"] ] ROW_PINS = [4, 14, 15, 17] # BCM numbering COL_PINS = [18, 27, 22, 23] # BCM numbering factory = rpi_gpio.KeypadFactory() # iniciliacizacion del metodo de teclado keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS) pygame.mixer.pre_init() pygame.mixer.init() pygame.init() def inicializa_sistema(): # inicicializacion de variables a False o neutro global FLAG_START_DISPARO global FLAG_START_IMPACTO global FLAG_START_MELODIA global FLAG_JUEGO_TERMINADO global FLAG_MENU