I need arduino code help. It gives me an error?

I am making a new code for my robot and when i verify it an error comes up. the error is
 " error expected constructor, destructor, or type conversion before '(' token" here is the code

// Arduino : Tumbler
// pin 9 ---- pin 6
// pin 10 --- pin 7
// pin 3 ---- pin 11
// pin 11 --- pin 10
// ground --- pin 2 (ground)
//
//

int switchPin= 2; // Right bump switch on pin 2
int swval= HIGH; // Variable for reading switch status
int RightFwd = 3; // PWM Output to go Foward on Right Wheel
int RightRev = 11; // PWM Output to go Reverse on Right Wheel
int LeftFwd = 9; // PWM Output to go Forward on Left Wheel
int LeftRev = 10; // PWM Output to go Reverse on Left Wheel

int delaytime = 2000; // delay between steps
int speedval = 145; // speed forward and reverse, at 50% (of 255 max)



void setup()
{
pinMode(switchPin, INPUT); // Sets the digital pin as input
pinMode(RightFwd, OUTPUT);
digitalWrite(RightFwd, LOW); // Make sure Output is initally at LOW
pinMode(RightRev, OUTPUT);
digitalWrite(RightRev, LOW); // Make sure Output is initally at LOW
pinMode(LeftFwd, OUTPUT);
digitalWrite(LeftFwd, LOW); // Make sure Output is initally at LOW
pinMode(LeftRev, OUTPUT);
digitalWrite(LeftRev, LOW); // Make sure Output is initally at LOW

delay(delaytime);

}

void loop()
{



analogWrite(LeftRev, 0);
analogWrite(LeftFwd, speedval); // turns on the left wheel in forward direction at the speed value
analogWrite(RightRev, 0);
analogWrite(RightFwd, speedval); // turns on the right wheel in forward direction at the speed value

delay(delaytime);

analogWrite(LeftFwd, 0); // turns off the left wheel
analogWrite(RightFwd, 0); // turns off the right wheel

delay(delaytime);
}

digitalWrite(switchPin, HIGH); // Sets the pin to high
swval = digitalRead(switchPin); // Read input value and store it
if (swval == LOW) {
analogWrite(LeftFwd, 0); // turns off the left wheel
analogWrite(RightFwd, 0); // turns off the right wheel
analogWrite(LeftRev, 0); // turns off left wheel
analogWrite(RightRev, 0); // turns off right wheel
analogWrite(LeftRev, speedval); // turns on left wheel rev
analogWrite(RightRev, speedval); // turns on right wheel rev
delay(800); // 800 milliseconds
analogWrite(LeftRev, 0); // turns off left wheel
analogWrite(RightRev, 0); // turns off right wheel
analogWrite(LeftFwd, speedval); // turns on left wheel
analogWrite(RightFwd, speedval); // turns on right wheel
}


Willard2.07 years ago
See my answer to your other question, you end "void loop()" before the "digitalWrite(switchPin,HIGH);" line.  Remove the "}" below "delay(delaytime); 
Your last 2 lines should look like this:

analogWrite(LeftFwd, speedval); // turns on left wheel
analogWrite(RightFwd, speedval); // turns on right wheel
}
}

The first "}" will close your if statment, the second "}" will close the void loop()
TOCO (author) 7 years ago
I forgot to mention that the error came up on the line below. digitalWrite(switchPin, HIGH); // Sets the pin to high
orksecurity7 years ago
Most compilers will also tell you which line, and usually which column, the error was detected at. . That may not be the actual problem, but it gives you a starting point to work backward from.

Sometimes temporarily commenting out blocks of code can help to isolate the problem.

(I haven't looked at the code in any detail, so I don't have a direct answer.... and it's better for you in the long run to learn how to find and resolve these.)