Guest
Public paste!

Untitled

By: a guest | Jan 12th, 2010 | Syntax: C | Size: 1.15 KB | Hits: 307 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. // Troy Watson Arduino Powered Chicken Coop Door
  2. // Waits for the sun to come up, turns a servo to open a drawbridge then waits and closes the bridge.
  3.  
  4. #include <Servo.h>
  5.  
  6. Servo servo0;  // create servo object
  7.  
  8. int sensVal = 0;  // analog pin used for light sensor
  9. int rotateDeg = 1080;    // number of degrees to lower drawbrigde
  10. int darkVal = 55;
  11.  
  12. void servoUp()
  13. {
  14.   servo0.write(rotateDeg); //tells the servo to turn out the winch
  15. }
  16.  
  17. void servoDown()
  18. {
  19.   servo0.write(-1*rotateDeg);  //writes the servo to turn back up?
  20. }
  21.  
  22. void setup()
  23. {
  24.   servo0.attach(9);  // attaches the servo on pin 9 to the servo object
  25. }
  26.  
  27. void loop()
  28. {
  29.   if (sensVal > darkVal){                      // duh
  30.         delay(360000);                         // waits 6 minutes
  31.         if (sensVal > darkVal){                // checks the sensor again to make sure its really the sun not just some retard in the neighbors driveway
  32.               servoDown();                     // lets door fall open gracefully
  33.               delay(43200000);                 // waits 12 hours.
  34.               servoUp();                       // pulls door back up
  35.         }
  36.   }
  37. }