Advertisement
Guest User

Untitled

a guest
Nov 6th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo vrataServo; //door servo
  4. Servo rukaServo; //hand servo
  5.  
  6. const int vrataPin = 10; //pin for door
  7. const int rukaPin = 11; //pin for hand
  8. int prekidacPin = 2; //switch on/off pin
  9.  
  10. int pozicijaRuka = 0; //position hand
  11. int pozicijaVrata = 0; //position door
  12. //I will change this values later when my servo comes.
  13.  
  14. int pozicija = 0; // position of hand and door
  15.  
  16. void setup()
  17. {
  18. Serial.begin(9600);
  19. pinMode(prekidacPin, INPUT); //switch on/off is set to INPUT mode
  20. //Attaching door and hand servo to pin 10, 11 and write position of them
  21. rukaServo.attach(rukaPin);
  22. vrataServo.attach(vrataPin);
  23. rukaServo.write(pozicijaRuka);
  24. vrataServo.write(pozicijaVrata);
  25. }
  26.  
  27. void loop()
  28. {
  29. if(digitalRead(prekidacPin) == HIGH) //if the switch is on
  30. {
  31. pokreniServo(); //start moving hand and door
  32. }
  33. }
  34.  
  35. void pokreniServo()
  36. {
  37. //open door
  38. for(pozicija = 80; pozicija < 155; pozicija += 3)
  39. {
  40. vrataServo.write(pozicija);
  41. delay(15);
  42. }
  43. //open hand
  44. for(pozicija = 0; pozicija < 129; pozicija += 4)
  45. {
  46. rukaServo.write(pozicija);
  47. delay(15);
  48. }
  49. //Hide hand
  50. for(pozicija = 129; pozicija >= 0; pozicija -= 4)
  51. {
  52. rukaServo.write(pozicija);
  53. delay(15);
  54. }
  55. //Hide door
  56. for(pozicija = 155; pozicija >= 80; pozicija -= 3)
  57. {
  58. vrataServo.write(pozicija);
  59. delay(15);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement