# MicroPython on a Raspberry Pi Pico W in Wokwi simulation.
# Warning: This is not even in beta, things might change.
#
# The code is just a small test.
#
# Code from here:
# https://electrocredible.com/raspberry-pi-pico-serial-uart-micropython/
import select
import sys
import time
import machine
# Create an instance of a polling object
poll_obj = select.poll()
# Register sys.stdin (standard input) for monitoring read events with priority 1
poll_obj.register(sys.stdin,1)
sys.stdout.write("Hello\n")
sys.stdout.write("Type a number 0...9\n")
# Sending out text does not work well, this delay helps.
time.sleep(0.1)
sys.stdout.write("Be sure to select the Serial Monitor field in your browser\n")
while True:
# Check if there is any data available on sys.stdin without blocking
if poll_obj.poll(0):
# Read one character from sys.stdin
ch = sys.stdin.read(1)
# Check if the character read is a number
if (ch>='0') and (ch<'9'):
print ("You typed the number: " )
print (ch)
print ("\n")
# Small delay to avoid high CPU usage in the loop
time.sleep(0.01)