--- /dev/null
+/*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+int left_echo_pin = 11;
+int left_trigger_pin = 12;
+
+int ping_microseconds = 0;
+double sound_cm_per_microsecond_at_sea_level = 0.034029;
+int count = 0;
+
+void setup(){
+ Serial.begin(9600);
+ pinMode(left_echo_pin, INPUT);
+ pinMode(left_trigger_pin, OUTPUT);}
+
+void loop(){
+ // make sure trigger pin is off, a.k.a. LOW
+ digitalWrite(left_trigger_pin, LOW);
+ delayMicroseconds(2);
+
+ // send a 10 microsecond HIGH pulse to the trigger pin
+ digitalWrite(left_trigger_pin, HIGH);
+ delayMicroseconds(10); // leave the pin on for 10 microseconds
+ digitalWrite(left_trigger_pin, LOW);
+
+ ping_microseconds = pulseIn(left_echo_pin, HIGH);
+
+ // wait for the sonar sensor hardware to recover from pinging
+ delayMicroseconds(50);
+
+ // print out the pulse time
+ Serial.print(ping_microseconds);
+ Serial.print(" = ping time (microseconds), ");
+ Serial.print(ping_microseconds * sound_cm_per_microsecond_at_sea_level / 2);
+ Serial.print(" = distance (cm). #");
+ Serial.println(count++);
+
+ // wait so it's easier to read the serial monitor.
+ // change delay to 0 for fullspeed.
+ // default is 333, which is about 1/3 of a second
+ delay(333);}
+++ /dev/null
-/*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-int right_echo_pin = 6;
-int right_trigger_pin = 7;
-
-int ping_microseconds = 0;
-double sound_cm_per_microsecond_at_sea_level = 0.034029;
-int count = 0;
-
-void setup(){
- Serial.begin(9600);
- pinMode(right_echo_pin, INPUT);
- pinMode(right_trigger_pin, OUTPUT);}
-
-void loop(){
- // make sure trigger pin is off, a.k.a. LOW
- digitalWrite(right_trigger_pin, LOW);
- delayMicroseconds(2);
-
- // send a 10 microsecond HIGH pulse to the trigger pin
- digitalWrite(right_trigger_pin, HIGH);
- delayMicroseconds(10); // leave the pin on for 10 microseconds
- digitalWrite(right_trigger_pin, LOW);
-
- ping_microseconds = pulseIn(right_echo_pin, HIGH);
-
- // wait for the sonar sensor hardware to recover from pinging
- delayMicroseconds(50);
-
- // print out the pulse time
- Serial.print(ping_microseconds);
- Serial.print(" = ping time (microseconds), ");
- Serial.print(ping_microseconds * sound_cm_per_microsecond_at_sea_level / 2);
- Serial.print(" = distance (cm). #");
- Serial.println(count++);
-
- // wait so it's easier to read the serial monitor.
- // change delay to 0 for fullspeed.
- // default is 333, which is about 1/3 of a second
- delay(333);}
int left_echo_pin = 11;
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){
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);
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.
--- /dev/null
+/*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// define which pins are connected to which components
+int left_motor_speed_pin = 8;
+int left_motor_forward_pin = 9;
+int left_motor_backward_pin = 10;
+
+void setup(){
+ // the arduino will change the voltage on these pins
+ // therefore, these pins are OUTPUT pins
+ pinMode(left_motor_speed_pin, OUTPUT);
+ pinMode(left_motor_forward_pin, OUTPUT);
+ pinMode(left_motor_backward_pin, OUTPUT);}
+
+void loop(){
+ digitalWrite(left_motor_backward_pin, LOW);
+ digitalWrite(left_motor_forward_pin, HIGH);
+ analogWrite(left_motor_speed_pin, 255);}
+++ /dev/null
-/*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-// define which pins are connected to which components
-int right_motor_speed_pin = 3;
-int right_motor_forward_pin = 4;
-int right_motor_backward_pin = 5;
-
-void setup(){
- // the arduino will change the voltage on these pins
- // therefore, these pins are OUTPUT pins
- pinMode(right_motor_speed_pin, OUTPUT);
- pinMode(right_motor_forward_pin, OUTPUT);
- pinMode(right_motor_backward_pin, OUTPUT);}
-
-void loop(){
- digitalWrite(right_motor_backward_pin, LOW);
- digitalWrite(right_motor_forward_pin, HIGH);
- analogWrite(right_motor_speed_pin, 255);}