Expected constructor, destructor, or type conversion before '(' token

I tried fixing this error but couldn't find a solution, please help me.
int motorpin=12;
void setup(){
pinMode(motorpin,OUTPUT);
}
void loop(){

}
digitalWrite(motorpin,HIGH);

Here is the error:
sketch_nov12a:9:13: error: expected constructor, destructor, or type conversion before '(' token
digitalWrite(motorpin,HIGH);
^
exit status 1
expected constructor, destructor, or type conversion before '(' token

First, please take a few minutes to read How to get the best out of this forum to see how to properly post code here.

int motorpin=12;
void setup(){
   pinMode(motorpin,OUTPUT);
}
void loop(){

}
digitalWrite(motorpin,HIGH);

See how much easier that is to read? And now look where your digitalWrite call is located. It's outside either of your declared functions. That's not proper C.

The loop function starts at the { and ends at the }. Everything after that is outside of any function where it doesn't belong. Move that digitalWrite line to inside of the function and it will compile.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.