Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TOTALUINTS 2
- byte trigPin[TOTALUINTS] = {6, 8};
- byte echoPin[TOTALUINTS] = {7.9};
- int trigPin2 = 8;
- int echoPin2 = 9;
- void setup() {
- Serial.begin (9600);
- for (byte i = 0; i < TOTALUINTS ; i++) {
- pinMode(trigPin[i], OUTPUT);
- pinMode(echoPin[i], INPUT);
- }
- }
- void runProcess(byte trigPin, byte echoPin) {
- long duration, distance;
- digitalWrite(trigPin, LOW); // Added this line
- delayMicroseconds(2); // Added this line
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10); // Added this line
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = (duration / 2) / 29.1;
- if (distance >= 500 || distance <= 0) {
- Serial.println("Distance Left: Out of range");
- }
- else {
- Serial.print("Distance Left: ");
- Serial.print(distance);
- Serial.print(" cm - ");
- float LDin = ( distance / 2.54 );
- Serial.print(LDin);
- Serial.println(" in");
- }
- }
- void loop() {
- for (byte i = 0; i < TOTALUINTS ; i++) {
- runProcess(trigPin[i], echoPin[i]);
- delay(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement