I'm using the Duemilanove with an ultrasonic sensor to measure distance. Everything was fine until I added code to light an LED when the sensor measures a specific distance. The code looks like this:
// this condition turns on the red LED indicator when the sensor measures 50 cm
if (cm == 50)
{
digitalWrite(ledPin1, HIGH);
delay(1000); // wait for a second
digitalWrite(ledPin1, LOW); // turn the red LED off
delay(1000); // wait for a second
}
else if (cm > 40 && cm < 50) // this condition turns on the yellow LED indicator when the sensor is approaching 50 cm
{
digitalWrite(ledPin2, HIGH);
delay(1500);
digitalWrite(ledPin2, LOW);
delay(1500);
}
delay(100);
}
When the "if" condition is met, the sensor stops transmitting. I need the sensor to continue functioning in the "if" control structure so that the LED can be on and the sensor continues measuring the distance. Any ideas on how I might do this?