Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_MotorShield.h>
- #include "utility/Adafruit_MS_PWMServoDriver.h"
- #include <Servo.h>
- Adafruit_MotorShield AFMS = Adafruit_MotorShield();
- Servo servo1;
- const int trigPinOne = 3;
- const int echoPinOne = 4;
- const int trigPinTwo = 5;
- const int echoPinTwo = 6;
- int SensorReading[] = {
- 0,0,0,0,0,0,0,0};
- long duration;
- int distance;
- int i;
- int ii;
- //---------------------------------------------------------------------
- void setup() {
- pinMode(trigPinOne, OUTPUT); // Sets the trigPin as an Output
- pinMode(echoPinOne, INPUT); // Sets the echoPin as an Input
- pinMode(trigPinTwo, OUTPUT); // Sets the trigPin as an Output
- pinMode(echoPinTwo, INPUT); // Sets the echoPin as an Input
- Serial.begin(9600);
- servo1.attach(10);
- }
- //---------------------------------------------------------------------
- void loop() {
- for (i = 0; i < 4; i = i + 1) {
- servo1.write((i*45));
- delay(250);
- DoScans();
- //delay(500);
- }
- for (i = 0; i < 8; i = i + 1) {
- Serial.print(SensorReading[i]);
- Serial.print(",");
- }
- Serial.println("");
- i = 0;
- }
- //---------------------------------------------------------------------
- void DoScans(){
- digitalWrite(trigPinOne, LOW);
- digitalWrite(trigPinTwo, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPinOne, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPinOne, LOW);
- duration = pulseIn(echoPinOne, HIGH);
- distance= duration*0.034/2;
- if (distance > 200){distance = 200;}
- SensorReading[i] = distance;
- delay(100);
- //--------------------------------------------------------------------
- digitalWrite(trigPinTwo, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPinTwo, LOW);
- duration = pulseIn(echoPinTwo, HIGH);
- distance= duration*0.034/2;
- if (distance > 200){distance = 200;}
- ii = i+4;
- SensorReading[ii] = distance;
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement