Advertisement
zinc55

Untitled

Feb 1st, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo; // create servo object to control a servo
  4. // a maximum of eight servo objects can be created
  5.  
  6. int pos = 0; // variable to store the servo position
  7. int ledPin = 4; // choose the pin for the LED
  8. int inputPin = 2; // choose the input pin (for PIR sensor)
  9. int pirState = LOW; // we start, assuming no motion detected
  10. int val = 0; // variable for reading the pin status
  11. int ledstate = 0; // the led should stay off after 1 detection
  12.  
  13. void setup()
  14. {
  15. myservo.attach(9); // attaches the servo on pin 9 to the servo object
  16. pinMode(ledPin, OUTPUT); // declare LED as output
  17. pinMode(inputPin, INPUT); // declare sensor as input
  18. Serial.begin(9600);
  19. }
  20.  
  21.  
  22. void loop()
  23. {
  24. for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 90 degrees
  25. {
  26. if ( digitalRead(inputPin == HIGH)) {
  27. digitalWrite(ledPin, LOW);
  28. myservo.write(pos);
  29. delay(30);
  30. }
  31. else {
  32. digitalWrite(ledPin, HIGH);
  33. }
  34. }
  35. for(pos = 90; pos>=1; pos -= 1) //goes from 180 to 0
  36. {
  37. if ( digitalRead(inputPin == HIGH)) {
  38. myservo.write(pos);
  39. digitalWrite(ledPin, LOW);
  40. delay(30);
  41. }
  42. else {
  43. digitalWrite(ledPin, HIGH);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement