Arduino undefined引用延迟

时间:2015-07-17 20:32:09

标签: arduino

#include <AFMotor.h>
#include <Servo.h>


AF_DCMotor leftback(1);
AF_DCMotor leftfront(2);
AF_DCMotor rightback(3);
AF_DCMotor rightfront(4);

int servopin = 34;
Servo servo;
int servopointer;

int trigpin = 22;
float longest_distance;
int echopin = 24;
float time;
float front_distance;
float left_distance;
float right_distance;
float speedofsound = 776.5;
String longest_distance_words;
String distance_heading;




void setup(){
  leftback.setSpeed(1000);
  leftfront.setSpeed(1000);
  rightback.setSpeed(1000);
  rightfront.setSpeed(1000);    
  servo.attach(servopin);
  pinMode(servopin,OUTPUT);
  pinMode(trigpin,OUTPUT);
  pinMode(echopin,INPUT);
  Serial.begin(9600);

}

void loop() {
  servo.write(90);
  delay(1000);
  servo.write(90);
  digitalWrite(trigpin,LOW);
  delayMicroseconds(2000);
  digitalWrite(trigpin,HIGH);
  delayMicroseconds(15);
  digitalWrite(trigpin,LOW);
  time = pulseIn(echopin,HIGH);
  time = time/1000000;//converts to seconds
  time = time/3600.;//converts to hours
  front_distance = speedofsound * time; // converts to miles and hours so mph
  front_distance = front_distance /2;//the ultrasonic sensor travels there and bounces back i only want there therfore i divide it by two
  front_distance = front_distance * 63360; // this converts teh distance to inches
  delay(500);

  servo.write(40);
  digitalWrite(trigpin,LOW);
  delayMicroseconds(2000);
  digitalWrite(trigpin,HIGH);
  delayMicroseconds(15);
  digitalWrite(trigpin,LOW);
  time = pulseIn(echopin,HIGH);
  time = time/1000000;//converts to seconds
  time = time/3600.;//converts to hours
  right_distance = speedofsound * time; // converts to miles and hours so mph
  right_distance = right_distance /2;//the ultrasonic sensor travels there and bounces back i only want there therfore i divide it by two
  right_distance = right_distance * 63360; // this converts teh distance to inches
  delay(500);

  servo.write(150);
  digitalWrite(trigpin,LOW);
  delayMicroseconds(2000);
  digitalWrite(trigpin,HIGH);
  delayMicroseconds(15);
  digitalWrite(trigpin,LOW);
  time = pulseIn(echopin,HIGH);
  time = time/1000000;//converts to seconds
  time = time/3600.;//converts to hours
  left_distance = speedofsound * time; // converts to miles and hours so mph
  left_distance = left_distance /2;//the ultrasonic sensor travels there and bounces back i only want there therfore i divide it by two
  left_distance = left_distance * 63360; // this converts teh distance to inches
  delay(500);

  if(left_distance > right_distance && left_distance > front_distance){
    longest_distance = left_distance;
    longest_distance_words = "Left Distance";
  }
  if(right_distance > left_distance && right_distance > front_distance){
    longest_distance = right_distance;
    longest_distance_words = "Right Distance";
  }
  if(front_distance > left_distance && front_distance > right_distance){
    longest_distance = front_distance;
    longest_distance_words = "Front Distance";
  }
  Serial.print("Front Distance is"); Serial.println(front_distance);
  Serial.print("Right Distance is "); Serial.println(right_distance);
  Serial.print("Left Distance is "); Serial.println(left_distance);
  Serial.print("The distance in inches is "); Serial.print(longest_distance_words); Serial.println(longest_distance);

  if(longest_distance > 4.00){
  rightback.run(BACKWARD);
  rightfront.run(BACKWARD);
  leftfront.run(BACKWARD);
  leftback.run(BACKWARD);
  delay(500);
  }

  if(longest_distance_words == "Left Distance"){
  rightback.run(BACKWARD);
  rightfront.run(BACKWARD);
  leftfront.run(FORWARD);
  leftback.run(FORWARD);
  }

  if(longest_distance_words == "Right Distance"){
  rightback.run(BACKWARD);
  rightfront.run(BACKWARD);
  leftfront.run(FORWARD);
  leftback.run(FORWARD);
  }

  if(longest_distance_words == "Left Distance"){
  rightback.run(BACKWARD);
  rightfront.run(BACKWARD);
  leftfront.run(FORWARD);
  leftback.run(FORWARD);
  }
}

错误发生在程序的所有延迟中,我之前从未见过这样的错误,因此我不知道如何修复它。该程序是一个障碍避免器,错误信息如下:

Arduino: 1.6.3 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

obstacle_avoider_robot_program.cpp.o: In function `loop':

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:43: undefined reference to `delay'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:45: undefined reference to `delayMicroseconds'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:47: undefined reference to `delayMicroseconds'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:55: undefined reference to `delay'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:58: undefined reference to `delayMicroseconds'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:60: undefined reference to `delayMicroseconds'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:69: undefined reference to `delay'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:72: undefined reference to `delayMicroseconds'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:73: undefined reference to `delayMicroseconds'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:83: undefined reference to `delay'

C:\Program Files (x86)\Arduino/obstacle_avoider_robot_program.ino:104: undefined reference to `delay'

C:\Users\peter\AppData\Local\Temp\build1607176699172334191.tmp/core.a(main.cpp.o): In function `main':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:32: undefined reference to `init'

collect2.exe: error: ld returned 1 exit status

Error compiling.

此报告将提供更多信息   “在编译期间显示详细输出”   在文件&gt;中启用偏好。

0 个答案:

没有答案