hi,
I am new to this so please bare with me...
I am trying to edit a programme written by somebody else and play around with it but i am confused why its not working .
I keep getting 0 instead of the programme adding my two distances ????
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration , distance, dis1, dis2, total ; // Duration used to calculate distance
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}
void loop() {
sonicboom();
distance = dis1;
sonicboom();
distance = dis2;
total = dis1 + dis2;
delay(500);
Serial.println(total);
}
void sonicboom() {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
distance == 0;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
if (distance >= maximumRange || distance <= minimumRange){
/* Turn LED ON to indicate "out of range" */
digitalWrite(LEDPin, HIGH);
//Delay 50ms before next reading*****************************.
delay(5000);
}
}
any help would be good ......i think i am close but i dont know where i am going wrong ????