compiler error, missing semi-colon

I am getting a compiler error saying a semi-colon is expected before motorPin, but I can't find where, or any other place with an error. It's a simple program; shown in its' entirety below. The error message is also attached.

All it is meant to do is run a motor (through a relay), upon the push of a button, for a set time.

Thanks in advance for any help.

int buttonPin = 8;
int motorPin = 11;

void setup() {
 pinMode (buttonPin, INPUT); 
 pinMode (motorPin, OUTPUT);
}

void loop() {
int runtime = 10000;//motor on time in milliseconds
int runspeed = 150;//for pwm, so 0 - 255 
int buttonState = digitalRead (buttonPin);
if (buttonState == 1){
  analogWrite motorPin (runspeed); //This line is highlighted as the error
  delay (runtime); 
}
}

ArduinoErrorHoneyStirrer.txt (4.77 KB)

Yep. Compiler was right:

  analogWrite motorPin (runspeed); //This line is highlighted as the error

analogWrite takes 2 parameters:

  analogWrite(motorPin, runspeed);

Ahhh, I'd put the bracket in the wrong place, thanks.

The error message gives you the exact line number, and character position where the error is....

ok, thanks. That helps.

is there a specific symbol or phrase which reliably appears before that part, so i can find it with my screen reader? I can search for a phrase and read from there, but error messages through a screen reader are taking some getting used to.

The full messages appear in the text box below the sketch. Each message starts with the full path to the sketch followed by a colon. If you search for ".ino:" that should get you to the interesting part of the message.

/Users/john/Documents/Arduino/sketch_feb28a/sketch_feb28a.ino: In function 'void loop()':
sketch_feb28a:14:15: error: expected ';' before 'motorPin'
   analogWrite motorPin (runspeed); //This line is highlighted as the error
               ^~~~~~~~
/Users/john/Documents/Arduino/sketch_feb28a/sketch_feb28a.ino:14:34: warning: statement is a reference, not call, to function 'analogWrite' [-Waddress]
   analogWrite motorPin (runspeed); //This line is highlighted as the error
                                  ^
/Users/john/Documents/Arduino/sketch_feb28a/sketch_feb28a.ino:14:34: warning: statement has no effect [-Wunused-value]
/Users/john/Documents/Arduino/sketch_feb28a/sketch_feb28a.ino:11:5: warning: unused variable 'runspeed' [-Wunused-variable]
 int runspeed = 150;//for pwm, so 0 - 255
     ^~~~~~~~
exit status 1
expected ';' before 'motorPin'

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