Skip to main content
added 84 characters in body
Source Link
L. Paw
  • 131
  • 1
  • 5

1) You should be using:

myservo.write(pos);

instead of

servo.write(pos);

for all of your methods.

2) Change:

include #include<Servo.h>

to

#include <Servo.h>

This code only verifies when it is run on the Mega or Uno board, so make sure you are using one of those boards.Good luck and welcome to the Arduino world!:)This code only verifies when it is run on certain boards, so make sure you are using one of those boards.Good luck and welcome to the Arduino world!:)*

*Verify that your board will work, I know Mega, Uno and Nano will function properly.

P.s. Here is the whole code in correct format:

#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++;
    myservo.write(pos);
    delay(15);
  }
  if ( (digitalRead(3) == HIGH) && (pos > 0)) {
    pos--;
    myservo.write(pos);
    delay(15);
  }
}

1) You should be using:

myservo.write(pos);

instead of

servo.write(pos);

for all of your methods.

2) Change:

include #include<Servo.h>

to

#include <Servo.h>

This code only verifies when it is run on the Mega or Uno board, so make sure you are using one of those boards.Good luck and welcome to the Arduino world!:)

P.s. Here is the whole code in correct format:

#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++;
    myservo.write(pos);
    delay(15);
  }
  if ( (digitalRead(3) == HIGH) && (pos > 0)) {
    pos--;
    myservo.write(pos);
    delay(15);
  }
}

1) You should be using:

myservo.write(pos);

instead of

servo.write(pos);

for all of your methods.

2) Change:

include #include<Servo.h>

to

#include <Servo.h>

This code only verifies when it is run on certain boards, so make sure you are using one of those boards.Good luck and welcome to the Arduino world!:)*

*Verify that your board will work, I know Mega, Uno and Nano will function properly.

P.s. Here is the whole code in correct format:

#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++;
    myservo.write(pos);
    delay(15);
  }
  if ( (digitalRead(3) == HIGH) && (pos > 0)) {
    pos--;
    myservo.write(pos);
    delay(15);
  }
}
Source Link
L. Paw
  • 131
  • 1
  • 5

1) You should be using:

myservo.write(pos);

instead of

servo.write(pos);

for all of your methods.

2) Change:

include #include<Servo.h>

to

#include <Servo.h>

This code only verifies when it is run on the Mega or Uno board, so make sure you are using one of those boards.Good luck and welcome to the Arduino world!:)

P.s. Here is the whole code in correct format:

#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++;
    myservo.write(pos);
    delay(15);
  }
  if ( (digitalRead(3) == HIGH) && (pos > 0)) {
    pos--;
    myservo.write(pos);
    delay(15);
  }
}