Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Created February 21, 2022 12:19
Show Gist options
  • Save mipsparc/86bd22c023b25ecd6ebbd3f87596e24c to your computer and use it in GitHub Desktop.
Save mipsparc/86bd22c023b25ecd6ebbd3f87596e24c to your computer and use it in GitHub Desktop.
Raspberry Pi PicoでUSBシリアル通信をするサンプルコード。
from machine import Pin, PWM
from time import sleep
pwm = PWM(Pin(15))
# 80kHz
pwm.freq(80000)
pwm.duty_u16(0)
line = ""
while True:
char = input()
line += char
if line.startswith("SOL") and line.endswith("EOL"):
print(line)
line = line.replace("SOL", "")
duty = line.replace("EOL", "")
pwm.duty_u16(int(duty))
line = ""
continue
if line.endswith("EOL"):
line = ""
if len(line) > 20:
line = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment