X-Git-Url: http://challenge-bot.com/repos/?a=blobdiff_plain;f=build-stages%2Fc_both_sonars%2Fc_both_sonars.ino;h=e39c0c4c20e3e2cc06ad3bc7dec6446452a7d4a8;hb=661ac21e0bd2e7a48c7bed6332e948873f4a2b23;hp=2d850ffbbd164acdb1bf54a4f86addfbe77ad76b;hpb=88c50c0cfc5e067de79c958ba8f834f5049cb723;p=challenge-bot diff --git a/build-stages/c_both_sonars/c_both_sonars.ino b/build-stages/c_both_sonars/c_both_sonars.ino index 2d850ff..e39c0c4 100644 --- a/build-stages/c_both_sonars/c_both_sonars.ino +++ b/build-stages/c_both_sonars/c_both_sonars.ino @@ -12,15 +12,16 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ +// yellow wire int right_echo_pin = 6; +// blue wire int right_trigger_pin = 7; +// yellow wire int left_echo_pin = 11; +// blue wire int left_trigger_pin = 12; -int right_ping_microseconds = 0; -int left_ping_microseconds = 0; -double sound_cm_per_microsecond_at_sea_level = 0.034029; int count = 0; void on(int pin){ @@ -47,6 +48,10 @@ int ping(int trigger, int echo){ delay(50); return ping_time;} +double ping_to_cm(int ping_microseconds){ + double sound_cm_per_microsecond_at_sea_level = 0.034029; + return ping_microseconds * sound_cm_per_microsecond_at_sea_level / 2;} + void setup(){ Serial.begin(9600); pinMode(right_echo_pin, INPUT); @@ -55,13 +60,19 @@ void setup(){ pinMode(left_trigger_pin, OUTPUT);} void loop(){ - right_ping_microseconds = ping(right_trigger_pin, right_echo_pin); + int left_ping_microseconds; + int right_ping_microseconds; + double left_distance; + double right_distance; left_ping_microseconds = ping(left_trigger_pin, left_echo_pin); + right_ping_microseconds = ping(right_trigger_pin, right_echo_pin); + left_distance = ping_to_cm(left_ping_microseconds); + right_distance = ping_to_cm(right_ping_microseconds); // print out the pulse time - Serial.print(right_ping_microseconds); - Serial.print(" = right ping microseconds, "); - Serial.print(left_ping_microseconds); - Serial.print(" = left ping microseconds. #"); + Serial.print(left_distance); + Serial.print(" = left distance (cm), "); + Serial.print(right_distance); + Serial.print(" = right distance (cm). line #"); Serial.println(count++); // wait so it's easier to read the serial monitor.