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
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.