Created
October 24, 2022 05:09
-
-
Save neosarchizo/5cd0a9b54867d473f3c85ea3a3c148a6 to your computer and use it in GitHub Desktop.
MicroPython - ESP32 서보모터 제어
This file contains 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 | |
servo = PWM(Pin(18), freq=50, duty=0) | |
def set_angle(angle): | |
global servo | |
servo.duty(int(((angle + 90) * 2 / 180 + 0.5) / 20 * 1023)) | |
set_angle(-90) | |
sleep(1) | |
set_angle(-45) | |
sleep(1) | |
set_angle(0) | |
sleep(1) | |
set_angle(45) | |
sleep(1) | |
set_angle(90) | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment