Im getting an error: expected unqualified-id before “{” token, can someone help?
Code follows
#include <Servo.h>
{
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo
void setup()
servoLeft.attach(9); // attaches the servo on pin 9 to the servo object
servoRight.attach(10);
int potpin0 = 0;
int potpin1 = 1; // analog pin used to connect the potentiometer
int val1;
int val0; // variable to read the value from the analog pin
{
servoLeft.attach(9); // attaches the servo on pin 9 to the servo object
servoRight.attach(10);
}
val1 = analogRead(potpin0);
val0 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179);
val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servoLeft.write(val0);
servoRight.write(val1); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
// Motion routines for forward, reverse, turns, and stop
Everything needs to be inside either the "setup" or "loop" functions. The way you define a function (including setup and loop) is:
return_type function_name(arguments) {
code
}
So, for setup() where it doesn't take any arguments and doesn't return anything, you'd say
void setup() {
// Whatever you want to run once
}
If, in the arduino IDE, you go to tools -> auto-format, that will indent everything for you so you can make sure you have a } for each {. However, you have to make sure they're in the correct spots yourself (for example, not having a { at the beginning of the program and putting it after setup() )
Yep… Looks like you got a little carried away with the whole { } concept… I think you meant to write something like this.
#include <Servo.h>
Servo servoLeft; // Define left servo
Servo servoRight; // Define right servo
int potpin0 = 0;
int potpin1 = 1; // analog pin used to connect the potentiometer
int val1;
int val0; // variable to read the value from the analog pin
void setup()
{
servoLeft.attach(9); // attaches the servo on pin 9 to the servo object
servoRight.attach(10);
}
void loop()
{
val1 = analogRead(potpin0);
val0 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179);
val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
servoLeft.write(val0);
servoRight.write(val1); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
// Motion routines for forward, reverse, turns, and stop
/example code and is not needed and is commented out
{
servoLeft.write(val0);
servoRight.write(val1);
delay(20);
}/