Skip to main content
Tweeted twitter.com/StackArduino/status/863109942651301888
added 84 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

I'm new to the Arduino world and am working on a sketch to run a servo up and down with a spdt switch. My code is :

include #include<Servo.h> int pos = 0;

Servo myservo; void setup() { pinMode(2, INPUT); pinMode(3, INPUT); myservo.attach(9); } void loop() { if (digitalRead(2) == HIGH && pos < 180) { pos++; servo.write(pos); delay(15); } if (digitalRead(3) == HIGH && pos > 0) { pos--; servo.write(pos); delay(15); } }

include #include<Servo.h>
int pos = 0;

Servo myservo;
void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  myservo.attach(9);
}
void loop() {
  if (digitalRead(2) == HIGH && pos < 180) {
    pos++;
    servo.write(pos);
    delay(15);
  }
  if (digitalRead(3) == HIGH && pos > 0) {
    pos--;
    servo.write(pos);
    delay(15);
  }
}

When I compile I get the "unexpected primary-expression before ';' token" error with exit status 1.

What am I doing wrong???

I'm new to the Arduino world and am working on a sketch to run a servo up and down with a spdt switch. My code is :

include #include<Servo.h> int pos = 0;

Servo myservo; void setup() { pinMode(2, INPUT); pinMode(3, INPUT); myservo.attach(9); } void loop() { if (digitalRead(2) == HIGH && pos < 180) { pos++; servo.write(pos); delay(15); } if (digitalRead(3) == HIGH && pos > 0) { pos--; servo.write(pos); delay(15); } }

When I compile I get the "unexpected primary-expression before ';' token" error with exit status 1.

What am I doing wrong???

I'm new to the Arduino world and am working on a sketch to run a servo up and down with a spdt switch. My code is :

include #include<Servo.h>
int pos = 0;

Servo myservo;
void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  myservo.attach(9);
}
void loop() {
  if (digitalRead(2) == HIGH && pos < 180) {
    pos++;
    servo.write(pos);
    delay(15);
  }
  if (digitalRead(3) == HIGH && pos > 0) {
    pos--;
    servo.write(pos);
    delay(15);
  }
}

When I compile I get the "unexpected primary-expression before ';' token" error with exit status 1.

What am I doing wrong???

Source Link

unexpected primary-expression before ';' token

I'm new to the Arduino world and am working on a sketch to run a servo up and down with a spdt switch. My code is :

include #include<Servo.h> int pos = 0;

Servo myservo; void setup() { pinMode(2, INPUT); pinMode(3, INPUT); myservo.attach(9); } void loop() { if (digitalRead(2) == HIGH && pos < 180) { pos++; servo.write(pos); delay(15); } if (digitalRead(3) == HIGH && pos > 0) { pos--; servo.write(pos); delay(15); } }

When I compile I get the "unexpected primary-expression before ';' token" error with exit status 1.

What am I doing wrong???