import rotaryio
import board
import digitalio
import time
button = digitalio.DigitalInOut(board.D5)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
encoder = rotaryio.IncrementalEncoder(board.D6, board.D9)
button_state = None
last_position = encoder.position
while True:
current_position = encoder.position
print(current_position)
last_position = current_position
if not button.value and button_state is None:
button_state = "pressed"
if button.value and button_state == "pressed":
print("Button pressed.")
button_state = None
time.sleep(0.05)
Weiterführende Links
Du hast noch nicht genug vom Thema?
Hier findest du noch weitere passende Inhalte zum Thema: