lcd = LCD(I2CPCF8574Interface(0x3f), num_rows=2, num_cols=16) button = DigitalInOut(board.D2) button.direction = Direction.INPUT button.pull = Pull.UP switch = DigitalInOut(board.D5) switch.direction = Direction.INPUT switch.pull = Pull.UP lcd.set_cursor_mode(CursorMode.LINE) press = False x = 0 while True: print(button.value) lcd.backlight = True if not button.value: if (press == False): press = True if not switch.value: x = x - 1 if switch.value: x = x + 1 print((0, )) if button.value: press = False lcd.set_cursor_pos(0, 0) lcd.print("Presses: ") lcd.set_cursor_pos(0, 10) lcd.print(str(x)) lcd.print(" ")
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16) button = DigitalInOut(board.D2) #make button pin button.direction = Direction.INPUT button.pull = Pull.UP #give power to button switch = DigitalInOut(board.D5) #make switch pin switch.direction = Direction.INPUT switch.pull = Pull.UP #give power to switch lcd.set_cursor_mode(CursorMode.LINE) press = False #press starts at false until proven otherwise x = 0 #starts at 0 while True: print(button.value) lcd.backlight = True #backlight is on if not button.value: if (press == False): press = True #if press does not equal false then press equals true if not switch.value: x = x -1 #if it does not equal switch value then it goes down by one if switch.value: x = x +1 #if it does equal switch value then it goes up by one print((0,)) if button.value: press = False #these print and display when it is false, which it is set to lcd.set_cursor_pos(0, 0) #sets cursor to start of LCD screen in the first row (0,0) lcd.print("Presses: ") lcd.set_cursor_pos(0, 10) #sets cursor to the end of LCD screen in the first row (0,10) lcd.print ( str (x)) lcd.print (" ")