Advertisement
sindi29

Untitled

May 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <Servo.h>
  2. int in1 = 10;
  3. int in2 = 11;
  4. Servo myservo; // create servo object to control a servo
  5. // twelve servo objects can be created on most boards
  6.  
  7. int pos = 0; // variable to store the servo position
  8. int open;
  9. int close;
  10. void setup() {
  11. myservo.attach(9);
  12. pinMode(in1, INPUT);
  13. pinMode(in2, INPUT);
  14. }
  15.  
  16. void loop() {
  17.  
  18. open=digitalRead(in1);
  19. close=digitalRead(in2);
  20. if(open==1) {
  21.  
  22. myservo.write(0); // tell servo to go to position in variable 'pos'
  23. delay(500); // waits 15ms for the servo to reach the position
  24. }
  25. else{
  26. if(close==1)
  27. {
  28.  
  29. myservo.write(180); // tell servo to go to position in variable 'pos'
  30. delay(500); // waits 15ms for the servo to reach the position
  31. }
  32. }
  33. delay(50);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement