Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- int in1 = 10;
- int in2 = 11;
- Servo myservo; // create servo object to control a servo
- // twelve servo objects can be created on most boards
- int pos = 0; // variable to store the servo position
- int open;
- int close;
- void setup() {
- myservo.attach(9);
- pinMode(in1, INPUT);
- pinMode(in2, INPUT);
- }
- void loop() {
- open=digitalRead(in1);
- close=digitalRead(in2);
- if(open==1) {
- myservo.write(0); // tell servo to go to position in variable 'pos'
- delay(500); // waits 15ms for the servo to reach the position
- }
- else{
- if(close==1)
- {
- myservo.write(180); // tell servo to go to position in variable 'pos'
- delay(500); // waits 15ms for the servo to reach the position
- }
- }
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement