Ai
2 Star 3 Fork 1

猴哥/esp8266-micropython

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
modular_sg90.py 632 Bytes
一键复制 编辑 原始数据 按行查看 历史
猴哥 提交于 2021-06-09 23:04 +08:00 . 加入sg90舵机
# sg90 舵机模块
from machine import Pin, PWM
def turn(cycle):
pwm0 = PWM(Pin(5)) # 从管脚创建PWM对象
pwm0.freq(50) # 设定频率
pwm0.duty(200) # 设置占空比
pwm0.duty(int((cycle) / 20 * 1023)) # 设置占空比
def turn_angle(angle):
if angle == b'WTF':
return
a = int(angle)
print(a)
if a == 0:
turn(0.5)
if a == 45:
turn(1)
if a == 90:
turn(1.5)
if a == 135:
turn(2)
if a == 180:
turn(2.5)
# PWM高电平占整个周期的时间 舵机旋转角度
# 0.5ms 0°
# 1ms 45°
# 1.5ms 90°
# 2ms 135°
# 2.5ms 180°
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/baozhuo/esp8266-micropython.git
git@gitee.com:baozhuo/esp8266-micropython.git
baozhuo
esp8266-micropython
esp8266-micropython
master

搜索帮助