Control your hub with your keyboard
This project shows how you to use keyboard input in your programs.
How it works
Your MicroPython programs can produce output using the
You can read keyboard presses using
stdin, as shown in the example below.
Then you can make your program choose different behaviors based on which key
# Import required MicroPython libraries. from usys import stdin from uselect import poll # Register the standard input so we can read keyboard presses. keyboard = poll() keyboard.register(stdin) while True: # Check if a key has been pressed. if keyboard.poll(0): # Read the key and print it. key = stdin.read(1) print("You pressed:", key)
This project was submitted by The Pybricks Team.