Arduino Uno:如何让它连续在图8中运行?

时间:2017-06-13 18:58:13

标签: arduino arduino-uno servo

我的任务是设计和实施软件,使你的Shield-Bot在“图8”中连续运行,其中两个环的直径至少为1英尺。

我已将以下代码放在一起,这使得第一次正确显示图8,但是在每次旋转之后它慢慢失去形式。 我需要以相同的方式进行每次旋转。

#include <Servo.h>

//declare servo motor variables
Servo leftServo;
Servo rightServo;

void loop() {
   //assign i/o pins to servo
  leftServo.attach(13);
  rightServo.attach(12);
  //Declare values for the first circle
  int leftFirtCirlceSpeed=1548;
  int rightFirstCircleSpeed=1300;

  //send pulse to each servo motor. Servo circles
  leftServo.writeMicroseconds(leftFirtCirlceSpeed);
  rightServo.writeMicroseconds(rightFirstCircleSpeed);
  delay(13000);

  //declare left/right servo int and assign these variables the pulse width so that the servo stops
  //int leftStop = 1500;
  //int rightStop = 1500;

  //send pulse to each servo motor. Servo stops
  //leftServo.writeMicroseconds(leftStop);
  //rightServo.writeMicroseconds(rightStop);
  //delay(100);

   //declare left/right servo int and assign these variables the pulse width so that the servo goes straight
  int leftStraight = 1700;
  int rightStraight = 1300;

  //send pulse to each servo motor. Servo goes straight
  leftServo.writeMicroseconds(leftStraight);
  rightServo.writeMicroseconds(rightStraight);
  delay(2000);

  //Declare values for the second circle
  int leftSecondCircleSpeed = 1700;
  int rightSecondCircleSpeed = 1458;

  //send pulse to each servo motor. Servo circles
  leftServo.writeMicroseconds(leftSecondCircleSpeed);
  rightServo.writeMicroseconds(rightSecondCircleSpeed);
  delay(9000);

  //leftServo.writeMicroseconds(leftStop);
  //rightServo.writeMicroseconds(rightStop);
  //delay(100);

  //send pulse to each servo motor. Servo goes straight
  leftServo.writeMicroseconds(leftStraight);
  rightServo.writeMicroseconds(rightStraight);
  delay(2000);
}

0 个答案:

没有答案