how to create delay function without using delay

Hi guys, my name is Scott. I’m working on a project in which the I use four sonar sensors (SR04) to detect objects from 0 to 3 meters away and output an audio cue for blind users to hear and possibly avoid them. The project is still very much in it infant state, and right now I’m trying to set my buzzer to buzz with different pattern depend on the parameter. For example 0 buzz if the object is farther than 3 meters. 1 for the object between 1.5 and 3, two buzzes for 1 to 1.5 and three buzzes for 0 to 1 m. I’m using newPing() and newTone(). To create a beeping noise, my buzzer needs to be on and off and delay for a period of time, but this mess up my program because my sonars depended on very precise timing. Is there a way for me to create beeping noise without using delay() function? thanks

sensor_array.ino (2.86 KB)

Goto File->Example->Digital->BlinkWithoutDelay, in that sketch you can see how to achieve it.

Also have a look at the Timer library http://playground.arduino.cc/Code/Timer

Is there a way for me to create beeping noise without using delay() function?

Sounds like you need to look at the BlinkWithoutDelay example. As you may gather, it has to do with turning an LED on and off without using delay() but it could equally turn a pin on and off at a much higher frequency.