当我用APP中的滑块控制其中一个舵机的时候就会出现其他舵机发生抖动,而且控制的那个舵机看起来也不是那么顺滑,请指教各位老师,大佬,高手!@
#include <SoftwareSerial.h>
#include <Servo.h>
Servo A;
Servo B;
Servo C;
Servo D;
Servo E;
Servo F;
int TX = 10;
int RX = 11;
SoftwareSerial lanya(TX, RX);
void setup()
{
A.attach(9);
delayMicroseconds(20);
B.attach(8);
delayMicroseconds(20);
C.attach(7);
delayMicroseconds(20);
D.attach(6);
delayMicroseconds(20);
E.attach(5);
delayMicroseconds(20);
F.attach(4);
delayMicroseconds(20);
Serial.begin(9600);
lanya.begin(9600);
}
void loop()
{
if(lanya.available()> 0 )
{
int zhi = lanya.read();
if(zhi>=0 && zhi<=45){
delayMicroseconds(20);
Serial.println(zhi);
int A_position = map(zhi, 0, 45, 0, 180);
A.write(A_position);
}
if(zhi>45 && zhi<=90){
delayMicroseconds(20);
Serial.println(zhi);
int B_position = map(zhi, 45, 90, 0, 180);
B.write(B_position);
}
if(zhi>90 && zhi<=135){
delayMicroseconds(20);
Serial.println(zhi);
int C_position = map(zhi, 90, 135, 0, 180);
C.write(C_position);
}
if(zhi>135 && zhi<=180){
delayMicroseconds(20);
Serial.println(zhi);
int D_position = map(zhi, 135, 180, 0, 180);
D.write(D_position);
}
if(zhi>180 && zhi<=225){
delayMicroseconds(20);
Serial.println(zhi);
int E_position = map(zhi, 180, 225, 0, 180);
E.write(E_position);
}
if(zhi>225 && zhi<=270){
delayMicroseconds(20);
Serial.println(zhi);
int F_position = map(zhi, 225, 270, 0, 180);
F.write(F_position);
}
}
}
#include <SoftwareSerial.h>
#include <Servo.h>
Servo A;
Servo B;
Servo C;
Servo D;
Servo E;
Servo F;
int TX = 10;
int RX = 11;
SoftwareSerial lanya(TX, RX);
void setup()
{
A.attach(9);
delayMicroseconds(20);
B.attach(8);
delayMicroseconds(20);
C.attach(7);
delayMicroseconds(20);
D.attach(6);
delayMicroseconds(20);
E.attach(5);
delayMicroseconds(20);
F.attach(4);
delayMicroseconds(20);
Serial.begin(9600);
lanya.begin(9600);
}
void loop()
{
if(lanya.available()> 0 )
{
int zhi = lanya.read();
if(zhi>=0 && zhi<=45){
delayMicroseconds(20);
Serial.println(zhi);
int A_position = map(zhi, 0, 45, 0, 180);
A.write(A_position);
}
if(zhi>45 && zhi<=90){
delayMicroseconds(20);
Serial.println(zhi);
int B_position = map(zhi, 45, 90, 0, 180);
B.write(B_position);
}
if(zhi>90 && zhi<=135){
delayMicroseconds(20);
Serial.println(zhi);
int C_position = map(zhi, 90, 135, 0, 180);
C.write(C_position);
}
if(zhi>135 && zhi<=180){
delayMicroseconds(20);
Serial.println(zhi);
int D_position = map(zhi, 135, 180, 0, 180);
D.write(D_position);
}
if(zhi>180 && zhi<=225){
delayMicroseconds(20);
Serial.println(zhi);
int E_position = map(zhi, 180, 225, 0, 180);
E.write(E_position);
}
if(zhi>225 && zhi<=270){
delayMicroseconds(20);
Serial.println(zhi);
int F_position = map(zhi, 225, 270, 0, 180);
F.write(F_position);
}
}
}