5 Star 39 Fork 5

robodyno/机器谱开源机器人

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
MotorAnalogBreath.ino 1.60 KB
Copy Edit Raw Blame History
song authored 2022-05-27 14:09 . add 026, U001
/*------------------------------------------------------------------------------------
版权说明: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-27 https://www.robotway.com/
-----------------------------------------------------
实验功能:
实现模拟量驱动直流电机缓慢加减速(类似于呼吸灯效果).
-----------------------------------------------------
实验接线:
直流电机引脚接D9,D10
------------------------------------------------------------------------------------*/
//程序初始化部分:初始化直流电机引脚.
void setup() {
pinMode( 10, OUTPUT); //将引脚10设置为输出模式
pinMode( 9, OUTPUT); //将引脚9设置为输出模式
}
//主程序部分:实现直流电机持续执行【缓慢加速到最大速度,再从最大速度减速到0】动作组。
//注意:直流电机模拟量速度范围为:【0~255】
void loop() {
for ( int i= 0; i<= 255 ; i++ ) //电机速度从0增大到255
{
analogWrite(9 , i);
analogWrite(10 , 0);
delay( 10 );
} //该for循环共耗时:256*10=2560毫秒.
delay( 3000 );//这里的3秒延时表示:电机保持255速度3秒
for ( int j= 255; j>= 0; j-- ) //电机速度从0增大到255
{
analogWrite(9 , j);
analogWrite(10 , 0);
delay( 10 );
} //该for循环共耗时:256*10=2560毫秒.
delay( 3000 );//这里的3秒延时表示:电机保持0速度3秒
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/robodyno/Robotway-Open-Robots.git
git@gitee.com:robodyno/Robotway-Open-Robots.git
robodyno
Robotway-Open-Robots
机器谱开源机器人
master

Search