“舵机控制”的版本间的差异
(Created page with "{| style="width: 800px;" |- | ==目的== 本教程将教大家如何用processing控制舵机旋转。 ==设备== *'''Microduino-Core''' *'''Microduino-FT232R''' *...") |
(→程序) |
||
| (未显示2个用户的5个中间版本) | |||
| 第1行: | 第1行: | ||
| + | {{Language |Servo_Control}} | ||
{| style="width: 800px;" | {| style="width: 800px;" | ||
|- | |- | ||
| 第7行: | 第8行: | ||
==设备== | ==设备== | ||
| − | *'''[[Microduino-Core]]''' | + | *'''[[Microduino-Core/zh]]''' |
| − | *'''[[Microduino- | + | *'''[[Microduino-USBTTL/zh]]''' |
*其他硬件设备 | *其他硬件设备 | ||
| 第20行: | 第21行: | ||
==程序== | ==程序== | ||
| − | + | [https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/processingServoControl processingServoControl] | |
| − | |||
==调试== | ==调试== | ||
| 第43行: | 第43行: | ||
arduino.pinMode(9, 5); | arduino.pinMode(9, 5); | ||
| − | // | + | //读取底部滑动条的值,来设置舵机的角度 |
void draw() | void draw() | ||
{ | { | ||
| − | + | background(0); | |
| − | + | noFill(); | |
| − | + | stroke(255); | |
| − | + | smooth(); | |
| − | + | float angle=map(pos, 0, 600, 0, 360); | |
| − | + | arc(width/2, height/2, 300, 300, turn, radians(angle)+turn); | |
| − | + | //Specify font to be used | |
| − | + | textFont(f, 48); | |
| − | + | //Display Text | |
| − | + | text ((int)angle, width/2-30, height/2+20); | |
| − | + | arduino.analogWrite(9, (int)constrain(angle, 0, 180)); | |
| − | |||
} | } | ||
| + | //滑动条移动事件处理 | ||
| + | void slider(float posValue) { | ||
| + | pos=(int)posValue; | ||
| + | println("Servo pos:"+pos); | ||
| + | } | ||
步骤三:下载代码并编译通过。 | 步骤三:下载代码并编译通过。 | ||
| − | + | 步骤四:运行后,左右移动底部滑动条,查看舵机有什么变化。 | |
==结果== | ==结果== | ||
| − | + | 在processing中会显示圆环,随着底部滑动条的移动,舵机也相应的转动: | |
| − | [[File: | + | [[File:processingServoControlResult1.jpg|600px|center|thumb]] |
| − | |||
==视频== | ==视频== | ||
2014年10月29日 (三) 07:24的最新版本
| Language | English |
|---|
目的本教程将教大家如何用processing控制舵机旋转。 设备
原理图程序调试步骤一:按着原理图搭建硬件环境,像这样:
本例需要两端的代码,Processing端和Microduino端 Microduino: 使用firmata的StandardFirmata程序,因为其实现了舵机控制方法 Processing: //在setup中定义串口通讯和设置pinMode arduino = new Arduino(this, Arduino.list()[0], 57600); //your offset may vary arduino.pinMode(9, 5); //读取底部滑动条的值,来设置舵机的角度 void draw()
{
background(0);
noFill();
stroke(255);
smooth();
float angle=map(pos, 0, 600, 0, 360);
arc(width/2, height/2, 300, 300, turn, radians(angle)+turn);
//Specify font to be used
textFont(f, 48);
//Display Text
text ((int)angle, width/2-30, height/2+20);
arduino.analogWrite(9, (int)constrain(angle, 0, 180));
}
//滑动条移动事件处理 void slider(float posValue) {
pos=(int)posValue;
println("Servo pos:"+pos);
}
步骤三:下载代码并编译通过。 步骤四:运行后,左右移动底部滑动条,查看舵机有什么变化。 结果在processing中会显示圆环,随着底部滑动条的移动,舵机也相应的转动: 视频 |


