コード例 #1
0
def main():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)

    GPIO.setup(Col1, GPIO.IN)
    GPIO.setup(Col2, GPIO.IN)
    GPIO.setup(Col3, GPIO.IN)

    GPIO.setup(Row1, GPIO.OUT)
    GPIO.setup(Row2, GPIO.OUT)
    GPIO.setup(Row3, GPIO.OUT)
    GPIO.setup(Row4, GPIO.OUT)

    for row in range(0, 4):
        GPIO.output(Rows[row], 1)

    lcd.lcd_begin(D4, D5, D6, D7, RS, EN)
    lcd.lcd_clear()
    lcd.send_cmd(0x0C)
    lcd.send_cmd(0x0F)
    GPIO.add_event_detect(
        Col1, GPIO.RISING,
        ScanISR)  # Setup interrupt to button pin, H->L, ISR, debounce time
    GPIO.add_event_detect(Col2, GPIO.RISING, ScanISR)
    GPIO.add_event_detect(Col3, GPIO.RISING, ScanISR)

    while True:
        time.sleep(1)
コード例 #2
0
def ISR(pin):
    global counter

    if pin == BUTTON:  # check if button pin generated interrupt
        counter = counter + 1
        lcd.lcd_clear()
        lcd.lcd_message(str(counter))
コード例 #3
0
def ScanISR(pin):
    global counter
    global counter2
    global push_flag
    global time_stamp

    time_now = time.time()

    column = pin - 14

    if (time_now -
            time_stamp) >= 0.03:  # check if button pin generated interrupt

        for row in range(0, 4):
            GPIO.output(Rows[row], 0)

        for row in range(0, 4):
            GPIO.output(Rows[row], GPIO.HIGH)
            if GPIO.input(pin) == GPIO.HIGH:
                message = Lookup[row][column]

                if message == "*":
                    lcd.lcd_clear()
                    break

                elif message == "#":
                    lcd.send_cmd(0xC0)
                    break

                else:
                    counter = counter + 1
                    if (counter == 8):
                        lcd.send_cmd(0xC0)

                    if (counter == 15):
                        lcd.lcd_clear()
                        counter = 0

                    lcd.lcd_message(message)
                    break

            GPIO.output(Rows[row], GPIO.LOW)

        for row in range(0, 4):
            GPIO.output(Rows[row], 1)

    time_stamp = time_now
コード例 #4
0
def ISR(pin):
    global counter
    global push_flag
    global time_stamp

    time_now = time.time()

    if pin == BUTTON and not push_flag and (
            time_now -
            time_stamp) >= 0.10:  # check if button pin generated interrupt
        push_flag = 1
        counter = counter + 1
        lcd.lcd_clear()
        lcd.lcd_message(str(counter))
        push_flag = 0

    time_stamp = time_now
コード例 #5
0
def fill_lcd_screen(firstRow, secondRow):
    lcd.lcd_clear()
    lcd.lcd_message(firstRow)
    lcd.send_cmd(0xC0)
    lcd.lcd_message(secondRow)