from machine import Pin
import time
LED_PIN = 26
led = Pin(LED_PIN, Pin.OUT)
print("พร้อมรับคำสั่ง (t สำหรับเปิด, f สำหรับปิด)")
while True:
command = input() # อ่านข้อมูลจากSerial
if command: # ตรวจสอบว่ามีข้อมูลเข้ามาหรือไม่
command = command.strip().lower() # ตัดช่องว่างและเปลี่ยนเป็นตัวพิมพ์เล็ก
if command == 't':
led.value(1) # เปิดไฟ LED (High)
print("LED: ON")
elif command == 'f':
led.value(0) # ปิดไฟ LED (Low)
print("LED: OFF")
else:
print("คำสั่งไม่ถูกต้อง กรุณาพิมพ์ 't' หรือ 'f'")
time.sleep(0.1)