5 Star 29 Fork 3

robodyno / 机器谱开源机器人

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Servo_Move_Other.ino 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
song 提交于 2022-05-30 17:39 . add M002
/*------------------------------------------------------------------------------------
版权说明:Copyright 2022 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.
Distributed under MIT license.See file LICENSE for detail or copy at
https://opensource.org/licenses/MIT
by 机器谱 2022-5-30 https://www.robotway.com/
----------------------------------------
实验功能:
实现舵机模组直接转动到某一角度.
本实验使用自定义舵机函数实现舵机转动.
----------------------------------------
实验接线:
舵机D3
------------------------------------------------------------------------------------*/
#define ServoPin 3 //定义舵机引脚号为D3
void setup() {
Serial.begin(9600);
pinMode(ServoPin, OUTPUT);
digitalWrite(ServoPin, LOW);//先保证拉低
}
void loop()
{
ServoControl(60); //舵机转到60度
delay(2000); //等待2秒
ServoControl(120); //舵机转到120度
delay(2000); //等待2秒
}
void ServoControl(int servoAngle)
{
double thisAngle = map(servoAngle, 0, 180, 500, 2500);//等比例角度值范围转换高电平持续时间范围
unsigned char i = 50;//50Hz 每秒的周期次数(周期/秒) 即1S 50 个周期 每个周期20ms
while (i--)
{
digitalWrite(ServoPin, HIGH);
delayMicroseconds(thisAngle); //高电平时间
digitalWrite(ServoPin, LOW);
delayMicroseconds(20000 - thisAngle);//每个周期20ms减去高电平持续时间
}
}
C++
1
https://gitee.com/robodyno/Robotway-Open-Robots.git
git@gitee.com:robodyno/Robotway-Open-Robots.git
robodyno
Robotway-Open-Robots
机器谱开源机器人
master

搜索帮助