Arduino舵机控制
2016-06-08 22:56
543 查看
普通舵机有3根线:GND(黑)、VCC(红)、Signal(黄)
![](https://images0.cnblogs.com/blog/90297/201304/12184733-ce736ba1a3ba4e0c8ea71e4eab200c49.png)
博客:http://www.cnblogs.com/xiaobo-Linux/
红色的是电源正极,黑色的是电源负极,白色的是信号线。有些舵机线是红棕橘三色,分别对应红黑白。
#include <Servo.h> Servo myservo; int pos = 90; void setup() { Serial.begin(9600); pinMode(4, OUTPUT); pinMode(5, OUTPUT); myservo.attach(9); }
![](https://images0.cnblogs.com/blog/90297/201304/12184733-ce736ba1a3ba4e0c8ea71e4eab200c49.png)
博客:http://www.cnblogs.com/xiaobo-Linux/
void loop() { char val = Serial.read(); if(val=='z') { pos+=30; // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position Serial.println(" servo_right"); } if(val=='x') { pos-=30; // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(150); // waits 15ms for the servo to reach the position Serial.println(" servo_left"); }
相关文章推荐
- UVa 11572 - Unique Snowflakes
- otauimgcmd
- CSR_uEnergy_SDK-2.4.2.1 e2cmd
- The request sent by the client was syntactically incorrect ()"解决办法
- bzoj1670 Usaco2006 Building the Moat护城河的挖掘 [凸包模板题]
- 使用NtUserBuildHwndList遍历窗口_win7x64
- mysql 慢查询分析工具:pt-query-digest 在mac 上的安装使用
- 1048 - Conquering Keokradong
- squirrel-sql通过phoenix-4.7.0连接windows中的hbase-1.1.3(二)
- UVA 11527 Unique Snowflakes
- poj 3061 Subsequence
- ( Leetcode 95 ) Unique Binary Search Trees II
- UIImagePickerController.h SDK 翻译
- UILabel 高度的自适应与获取
- QtQuick折腾结论之model delegate 的正确使用姿势
- IOS 多线程02-pthread 、 NSThread 、GCD 、NSOperationQueue、NSRunLoop
- QtQuick排坑(不定时更新)
- POJ 2524 Ubiquitous Religions
- 2016 UESTC Training for Math Problem E- 蹲在墙角画圈圈的愚人王
- LeetCode:N-Queens