-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo remote control
37 lines (30 loc) · 1.02 KB
/
servo remote control
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <Servo.h>
Servo myservo;
const int button1 = 2; // the number of the button1 pin
const int button2 = 3; // the number of the button2 pin
int State1 = 0; // variable for reading the button1 status
int State2 = 0; // variable for reading the button2 status
void setup()
{
Serial.begin(9600);
pinMode(button1, INPUT); // initialize button1 pin as an input
pinMode(button2, INPUT); // initialize button2 pin as an input
myservo.attach(11); // initialize servo on pin 11
}
void loop() {
State1 = digitalRead(button1);
State2 = digitalRead(button2);
// check if button1 is pressed.
// if the buttonState is HIGH
// turn servo tp 90 degrees
if (State1 == HIGH) {
myservo.write(0); // set servo to mid-point
Serial.println("B1 pressed");
Serial.println("Moved servo to 0 degrees");
}
else if (State2 == HIGH) {
myservo.write(90); // set servo back to beginning point
Serial.println("B2 pressed");
Serial.println("Moved servo to 90 degrees");
}
}