Created
February 21, 2022 12:19
-
-
Save mipsparc/86bd22c023b25ecd6ebbd3f87596e24c to your computer and use it in GitHub Desktop.
Raspberry Pi PicoでUSBシリアル通信をするサンプルコード。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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