GertSanders: hi Tim,
it did not compile properly (it did not find an ASSR symbol). I tried changing things to allow it to use Timer0, which is the 8 bit timer on this MCU (Timer2 is 16 bit). That also failed, but that is probably due to my poor understanding of the datasheet.
I do have another question: when ping_cm() is called, will it execute for the duration of time needed for the echo to register (or up to the time needed for MAX_DISTANCE) ? Does it basically only continue when either the echo is detected or the maximum wait time for MAX_DISTANCE expires ?
I use the SR-HC04 with a max distance of 150cm, and will be using it mostly for shorter distances, so that would mean that I can ping sensors every 89micro seconds (if I use 8 of them spread out to avoid false echo's).
Would be nice to get confirmation on this last question. Gert
ping_cm() uses blocking mode, so yes, it will wait till it gets a ping back or it exceeds the defined max distance. Remember it's not just what you set for the software as the max distance, there's the physical world to consider, and those pings may echo in the real world no matter how you set the max distance. In other words, you could still have echo and cross-talk issues even if you only care about shorter distances. Multiple sensors cause even more cross-talk and echo problems. Nothing a library can do about this, as you're dealing with the speed of sound, echos (the physical world) and the sensitivity of the sensors (hardware limitations).