i want to click gui print("On") led on bord on
data sent usb port
#Python
Code: Select all
import serial
import time
# Define the serial port and baud rate.
ser = serial.Serial('COM14', 9600)
def led_on_off():
user_input = input("\n Type on / off / quit : ")
if user_input =="on":
print("LED is on...")
time.sleep(0.1)
ser.write(b'H')
led_on_off()
elif user_input =="off":
print("LED is off...")
time.sleep(0.1)
ser.write(b'L')
led_on_off()
elif user_input =="quit" or user_input == "q":
print("Program Exiting")
time.sleep(0.1)
ser.write(b'L')
ser.close()
else:
print("Invalid input. Type on / off / quit.")
led_on_off()
time.sleep(2) # wait for the serial connection to initialize
led_on_off()
Code: Select all
import machine
import os
led = machine.Pin(2, machine.Pin,OUT)
uert = machine.UART(0, 115200)
os.dupterm(None, 1)
str = ''
whhile True:
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: :
str = sys.stdin.read()
if 'H' in str:
led.on()
elif 'L' in str:
led.off()