我们在以下代码中遇到此错误。我是这方面的初学者,所以请以简单的方式解释我们可能做错了什么。
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
int potpin1 = 0; // analog pin used to connect the potentiometer
int val1; // variable to read the value from the analog pin
int potpin2 = 1;
int val2;
int potpin3 = 2;
int val3;
int potpin4 = 3;
int val4;
int potpin5 = 4;
int val5;
void setup()
{
myservo1.attach(3); // attaches the servo on pin 9 to the servo object
myservo2.attach(5);
myservo3.attach(6);
myservo4.attach(9);
myservo5.attach(10);
}
void loop()
{
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val1); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 179);
myservo2.write(val2);
delay(15);
val3 = analogRead(potpin3);
val3 = map(val3, 0, 1023, 0, 179);
myservo3.write(val3);
delay(15);
val4 = analogRead(potpin4);
val4 = map(val4, 0, 1023, 0, 179);
myservo4.write(val4);
delay(15);
val5 = analogRead(potpin5);
val5 = map(val5, 0, 1023, 0, 179);
myservo5.write(val5);
delay(15);
}
答案 0 :(得分:1)
该代码在最新的Arduino IDE(在OSX上)编译得很好。您没有说明您所使用的平台或用于编译代码的方式。听起来你要么安装了Arduino IDE和libs,要么正在使用其他设置不正确的东西。