Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- int PhotocellPin = A0; // Set photocell and 10K ohm resistor to A0
- int PhotocellPin2 = A1; // Set photocell and 10K ohm resistor to A1
- int PhotocellReading; // The analog reading from the analog resistor divider A0
- int PhotocellReading2; // The analog reading from the analog resistor divider A1
- int CenterPos = 90;
- int FrontLeftUp = 0;
- int MiddleLeftUp = 0;
- int RearLeftUp = 0;
- int FrontRightForward = 180;
- int MiddleRightForward = 180;
- int RearRightForward = 180;
- Servo FrontServo; // Define Front servo
- Servo MiddleServo; // Define Middle servo
- Servo RearServo; // Define Rear servo
- void moveForward()
- {
- FrontServo.write(FrontRightForward);
- MiddleServo.write(MiddleRightForward);
- RearServo.write(RearRightForward);
- delay(125);
- FrontServo.write(CenterPos);
- MiddleServo.write(CenterPos);
- RearServo.write(CenterPos);
- delay(65);
- FrontServo.write(FrontLeftUp);
- MiddleServo.write(MiddleLeftUp);
- RearServo.write(RearLeftUp);
- delay(125);
- FrontServo.write(CenterPos);
- MiddleServo.write(CenterPos);
- RearServo.write(CenterPos);
- delay(65);
- }
- void setup() {
- Serial.begin(9600); // We'll send the information via the Serial monitor
- pinMode(13, OUTPUT); // Set led and 330 ohm resistor to digital pin 13
- pinMode(12, OUTPUT); // Set led2 to digital pin 12
- FrontServo.attach(3); // Set left servo to digital pin 3
- MiddleServo.attach(5); // Set Middle servo to digital pin 5
- RearServo.attach(11); // Set Right servo to digital pin 11
- }
- void loop() { // Loop through motion tests
- PhotocellReading = analogRead(PhotocellPin);
- Serial.print("Analog reading = ");
- Serial.println(PhotocellReading); // the pin a0 reading
- // We'll have a few threshholds, qualitatively determined
- if (PhotocellReading < 10) { // if the reading is less than 10,
- Serial.println(" - Dark"); // print its dark
- } else if (PhotocellReading < 200) { // if the reading is less than 200,
- Serial.println(" - Dim"); // print its dim
- } else if (PhotocellReading < 500) { // if the reading is less than 500,
- Serial.println(" - Light"); // print its light
- } else if (PhotocellReading < 800) { // if the reading is less than 800,
- Serial.println(" - Bright"); // print its bright
- } else { // if the reading is greater then 800,
- Serial.println(" - Very bright"); // print its very bright
- }
- delay(100);
- PhotocellReading2 = analogRead(PhotocellPin2);
- Serial.print("Analog reading2 = ");
- Serial.println(PhotocellReading2); // the pin a1 reading
- // We'll have a few threshholds, qualitatively determined
- if (PhotocellReading2 < 10) { // if the reading2 is less than 10,
- Serial.println(" - Dark"); // print its dark
- } else if (PhotocellReading2 < 200) { // if the reading2 is less than 200,
- Serial.println(" - Dim"); // print its dim
- } else if (PhotocellReading2 < 500) { // if the reading2 is less than 500,
- Serial.println(" - Light"); // print its light
- } else if (PhotocellReading2 < 800) { // if the reading2 is less than 800,
- Serial.println(" - Bright"); // print its bright
- } else { // if the reading2 is greater then 800,
- Serial.println(" - Very bright"); // print its very bright
- }
- delay(100);
- digitalWrite(13, HIGH); // Turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // Turn the LED2 on (HIGH is the voltage level)
- delay(1000); // Wait for one second (1000 ms)
- digitalWrite(13, LOW); // Turn the LED off by making the voltage LOW
- digitalWrite(12, LOW); // Turn the LED2 off by making the voltage LOW
- delay(500); // Wait for half a second (500 ms)
- {
- moveForward();
- delay(150); //time between each step taken, speed of walk
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement