Skip to content

Instantly share code, notes, and snippets.

@neosarchizo
Created October 24, 2022 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neosarchizo/5cd0a9b54867d473f3c85ea3a3c148a6 to your computer and use it in GitHub Desktop.
Save neosarchizo/5cd0a9b54867d473f3c85ea3a3c148a6 to your computer and use it in GitHub Desktop.
MicroPython - ESP32 서보모터 제어
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