I currently have an ultrasonic range finder programmed to turn a servo within a distance <20. I also want this same sensor to operate my LEDs and was wondering if I can have that operation run in tandem?
The LEDs are on a separate arduino and are programmed to operate in succession as an individual comes closer and closer to the object. Therefore, I need the sensor to fire each specified pin for the LEDs as indicated, but still turn the motor. How can I combine these functions?
Thanks.
example code for LED using serial.print:
if (howfar < 50) { // start of in range actions
if (howfar > 40) { // "far"
digitalWrite(9, HIGH); // sets the red LED on
}
else if (howfar > 20) // "medium"
{
digitalWrite(10, HIGH); // sets the yellow LED on
}
else // "near"
{
digitalWrite(11, HIGH); // sets the green LED on
}
} // end of in-range actions