6 达人 1天前 101次点击
#include
Servo R1; Servo R2;
Servo L1; Servo L2;
Servo RL1; Servo RL2;
Servo LL1; Servo LL2;
void setup(){
Serial.begin(115200);
R1.attach(13); R2.attach(12);
L1.attach(14); L2.attach(27);
RL1.attach(26); RL2.attach(25);
LL1.attach(33); LL2.attach(32);
initPose();
}
void initPose(){
R1.write(90); R2.write(90);
L1.write(90); L2.write(90);
RL1.write(90); RL2.write(80);
LL1.write(90); LL2.write(80);
delay(1000);
}
void armRight(){
R1.write(130); R2.write(40); delay(800); initPose();
}
void armLeft(){
L1.write(50); L2.write(140); delay(800); initPose();
}
void handShake(){
R1.write(110); R2.write(60); delay(500);
R2.write(30); delay(300); R2.write(60);
delay(300); R2.write(30); delay(300);
initPose();
}
void standUp(){
RL2.write(90); LL2.write(90); delay(1000);
}
void loop(){
if(Serial.available()){
String cmd = Serial.readStringUntil('\n');
if(cmd=="右胳膊") armRight();
if(cmd=="左胳膊") armLeft();
if(cmd=="握手") handShake();
if(cmd=="站起来") standUp();
if(cmd=="复位") initPose();
}
}
控制动作的吧,不过这玩意不靠谱。