本帖最后由 今天微冷 于 2013-4-8 21:56 编辑
写了一个蓝牙控制舵机(安在机械臂上)的程序,通过手机蓝牙发送数字N=1或10命令舵机转动,但是测试中并没有达到控制效果,程序很简单,如下
#include<Servo.h>
Servo servo1,servo2,servo3,servo4,servo5,servo6;
//servo1-4 从下到上控制臂,5爪旋转,6爪松紧
int n,data;
void setup()
{
servo1.attach(2);
servo2.attach(3);
servo3.attach(4);
servo4.attach(5);
servo5.attach(8);
servo6.attach(10);
Serial.begin(9600);//设置波特率为9600
}
void loop()
{
servo1.write(90);
servo2.write(90);
servo3.write(100);
servo4.write(0);
servo5.write(0);
servo6.write(90);
delay(1000);
n=Serial.read();;
if(n=10)
{
servo1.write(90);
servo2.write(90);
servo3.write(100);
servo4.write(0);
servo5.write(50);
servo6.write(30);
delay(1000);
}
else if(n=1)
{
servo1.write(90);
servo2.write(90);
servo3.write(100);
servo4.write(30);
servo5.write(50);
servo6.write(30);
delay(1000);
}
else
{
servo1.write(90);
servo2.write(90);
servo3.write(100);
servo4.write(0);
servo5.write(0);
servo6.write(90);
delay(1000);
}
}
请问哪里出问题了么? |