Hi,
I am pretty much a newbie to coding and often don't fully understand what I am doing!!!
I am developing a previous project where I am controlling a video wall by an object (a human) moving towards and away from the wall. I am using an HC-S04 to derive distance measurements and dividing distance into zones...ie 4m to 3.5m, 3.5m to 3m down to 0.05m. When the object lies within a zone, relays are activated which are inputted to the video wall DMX controller to change the 'scene'.
The video wall works great and as designed.
At the moment it is installed in a very large space, the maximum distance is set at 4m (max effective distance of the HC-S04) within the NewPing library constructor it is set so: NewPing sonar(trigger_pin, echo_pin [, max_cm_distance]);
My mate who's video wall it is, is very happy and now wants to take it to different venues where the maximum distance may well be less than 4m.
I want to put a pot into my project which can be adjusted to change and 'compress' the distance zones and set the maximum distance in a smaller venue if it is less than 4m...
Unfortunately, I reached a brick wall immediately because max distance is not a variable and is set in the constructor.
I think I can do the whole ping thing 'manually' without using the NewPing library but was wondering if it were possible to use the library as it works very well.
Can any of you amazingly brilliant and helpful folk out there point me in the right direction please?
Cheers in advance
Steve
Edit NewPing.h in the library to move the declaration of "set_max_distance()" from the "private:" section to the "public:" section. Then you can call it to set a new maximum distance. It uses the stored value for each ping so there should be no problem changing the value whenever you want.
It might be easiest just to add a test for sonar return values greater than maximum "compressed distance" and set the return distance to the same value as "no return".
The purpose of the maximum distance parameter is to bound the amount of time the sensor will wait for a return. If the time for 4 meters is fast enough there's no compelling reason to change it.
John, Mark,
Thanks very much.
I'm going to try both methods to learn more about how to do this stuff.
I am learning all this at the age of 60 and am becoming a big fan!
Cheers
Steve