Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. int PhotocellPin = A0; // Set photocell and 10K ohm resistor to A0
  4. int PhotocellPin2 = A1; // Set photocell and 10K ohm resistor to A1
  5. int PhotocellReading; // The analog reading from the analog resistor divider A0
  6. int PhotocellReading2; // The analog reading from the analog resistor divider A1
  7. int CenterPos = 90;
  8. int FrontLeftUp = 0;
  9. int MiddleLeftUp = 0;
  10. int RearLeftUp = 0;
  11. int FrontRightForward = 180;
  12. int MiddleRightForward = 180;
  13. int RearRightForward = 180;
  14.  
  15. Servo FrontServo; // Define Front servo
  16. Servo MiddleServo; // Define Middle servo
  17. Servo RearServo; // Define Rear servo
  18.  
  19. void moveForward()
  20. {
  21. FrontServo.write(FrontRightForward);
  22. MiddleServo.write(MiddleRightForward);
  23. RearServo.write(RearRightForward);
  24. delay(125);
  25.  
  26. FrontServo.write(CenterPos);
  27. MiddleServo.write(CenterPos);
  28. RearServo.write(CenterPos);
  29. delay(65);
  30.  
  31. FrontServo.write(FrontLeftUp);
  32. MiddleServo.write(MiddleLeftUp);
  33. RearServo.write(RearLeftUp);
  34. delay(125);
  35.  
  36. FrontServo.write(CenterPos);
  37. MiddleServo.write(CenterPos);
  38. RearServo.write(CenterPos);
  39. delay(65);
  40. }
  41.  
  42. void setup() {
  43. Serial.begin(9600); // We'll send the information via the Serial monitor
  44. pinMode(13, OUTPUT); // Set led and 330 ohm resistor to digital pin 13
  45. pinMode(12, OUTPUT); // Set led2 to digital pin 12
  46.  
  47. FrontServo.attach(3); // Set left servo to digital pin 3
  48. MiddleServo.attach(5); // Set Middle servo to digital pin 5
  49. RearServo.attach(11); // Set Right servo to digital pin 11
  50. }
  51.  
  52. void loop() { // Loop through motion tests
  53.  
  54. PhotocellReading = analogRead(PhotocellPin);
  55.  
  56. Serial.print("Analog reading = ");
  57. Serial.println(PhotocellReading); // the pin a0 reading
  58.  
  59. // We'll have a few threshholds, qualitatively determined
  60. if (PhotocellReading < 10) { // if the reading is less than 10,
  61. Serial.println(" - Dark"); // print its dark
  62. } else if (PhotocellReading < 200) { // if the reading is less than 200,
  63. Serial.println(" - Dim"); // print its dim
  64. } else if (PhotocellReading < 500) { // if the reading is less than 500,
  65. Serial.println(" - Light"); // print its light
  66. } else if (PhotocellReading < 800) { // if the reading is less than 800,
  67. Serial.println(" - Bright"); // print its bright
  68. } else { // if the reading is greater then 800,
  69. Serial.println(" - Very bright"); // print its very bright
  70. }
  71. delay(100);
  72.  
  73. PhotocellReading2 = analogRead(PhotocellPin2);
  74.  
  75. Serial.print("Analog reading2 = ");
  76. Serial.println(PhotocellReading2); // the pin a1 reading
  77.  
  78. // We'll have a few threshholds, qualitatively determined
  79. if (PhotocellReading2 < 10) { // if the reading2 is less than 10,
  80. Serial.println(" - Dark"); // print its dark
  81. } else if (PhotocellReading2 < 200) { // if the reading2 is less than 200,
  82. Serial.println(" - Dim"); // print its dim
  83. } else if (PhotocellReading2 < 500) { // if the reading2 is less than 500,
  84. Serial.println(" - Light"); // print its light
  85. } else if (PhotocellReading2 < 800) { // if the reading2 is less than 800,
  86. Serial.println(" - Bright"); // print its bright
  87. } else { // if the reading2 is greater then 800,
  88. Serial.println(" - Very bright"); // print its very bright
  89. }
  90. delay(100);
  91.  
  92. digitalWrite(13, HIGH); // Turn the LED on (HIGH is the voltage level)
  93. digitalWrite(12, HIGH); // Turn the LED2 on (HIGH is the voltage level)
  94. delay(1000); // Wait for one second (1000 ms)
  95.  
  96. digitalWrite(13, LOW); // Turn the LED off by making the voltage LOW
  97. digitalWrite(12, LOW); // Turn the LED2 off by making the voltage LOW
  98. delay(500); // Wait for half a second (500 ms)
  99.  
  100. {
  101. moveForward();
  102. delay(150); //time between each step taken, speed of walk
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement