Well I have the Arduino Mega (ATmega1280)
I'm a bit of a novice, so don't expect much from me for now lol
Well I am having a problem with the code that I modified from the example code in the tutorial section of using a potentiometer as an input to control a servo.
I want to verify the code before uploading it the board, but keep getting a "val_x was not declared in this scope" error.
Heres the code and the part highlighted is where it is.
#include <Servo.h>
Servo servo1; // create servo object for servo1
Servo servo2; // create servo object for servo2
Servo servo3; // create servo object for servo3
Servo servo4; // create servo object for servo4
Servo servo5; // create servo object for servo5
Servo servo6; // create servo object for servo6
Servo servo7; // create servo object for servo7
Servo servo8; // create servo object for servo8
Servo servo9; // create servo object for servo9
Servo servo10; // create servo object for servo10
int potpin0 = 0; // analog pin used to connect the potentiometer
int potpin1 = 1; // analog pin used to connect the potentiometer
int potpin2 = 2; // analog pin used to connect the potentiometer
int potpin3 = 3; // analog pin used to connect the potentiometer
int potpin4 = 4; // analog pin used to connect the potentiometer
int potpin5 = 5; // analog pin used to connect the potentiometer
int potpin6 = 6; // analog pin used to connect the potentiometer
int potpin7 = 7; // analog pin used to connect the potentiometer
int potpin8 = 8; // analog pin used to connect the potentiometer
int potpin9 = 9; // analog pin used to connect the potentiometer
int val_0; // variable to read from analog pin
int val_1; // variable to read from analog pin
int val_2; // variable to read from analog pin
int val_3; // variable to read from analog pin
int val_4; // variable to read from analog pin
int val_5; // variable to read from analog pin
int val_6; // variable to read from analog pin
int val_7; // variable to read from analog pin
int val_8; // variable to read from analog pin
int val_9; // variable to read from analog pin
void setup()
{
servo1.attach(2); // attaches the servo on pin 2 to the servo object
servo1.attach(3); // attaches the servo on pin 3 to the servo object
servo1.attach(4); // attaches the servo on pin 4 to the servo object
servo1.attach(5); // attaches the servo on pin 5 to the servo object
servo1.attach(6); // attaches the servo on pin 6 to the servo object
servo1.attach(7); // attaches the servo on pin 7 to the servo object
servo1.attach(8); // attaches the servo on pin 8 to the servo object
servo1.attach(9); // attaches the servo on pin 9 to the servo object
servo1.attach(10); // attaches the servo on pin 10 to the servo object
servo1.attach(11); // attaches the servo on pin 11 to the servo object
}
void loop()
{
val_0 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val_0 = map(val, 0, 511, 0, 179);
servo1.write(val_0); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_1 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val_1 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo2.write(val_1); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_2 = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023)
val_2 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo3.write(val_2); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_3 = analogRead(potpin4); // reads the value of the potentiometer (value between 0 and 1023)
val_3 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo4.write(val_3); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_4 = analogRead(potpin5); // reads the value of the potentiometer (value between 0 and 1023)
val_4 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo5.write(val_4); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_5 = analogRead(potpin6); // reads the value of the potentiometer (value between 0 and 1023)
val_5 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo6.write(val_5); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_6 = analogRead(potpin7); // reads the value of the potentiometer (value between 0 and 1023)
val_6 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo7.write(val_6); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_7 = analogRead(potpin8); // reads the value of the potentiometer (value between 0 and 1023)
val_7 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo8.write(val_7); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_8 = analogRead(potpin9); // reads the value of the potentiometer (value between 0 and 1023)
val_8 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo9.write(val_8); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
val_9 = analogRead(potpin10); // reads the value of the potentiometer (value between 0 and 1023)
val_9 = map(val, 0, 511, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servo10.write(val_9); // sets the servo position according to the scaled value
delay(10); // waits for the servo to get there
}
I suspect that all the other similar lines will have the same errors