From: daniel watson Date: Tue, 29 Jul 2014 07:21:27 +0000 (-0700) Subject: start with left sonar and left motor X-Git-Url: http://challenge-bot.com/repos/?p=challenge-bot;a=commitdiff_plain;h=35ffc3435298c78927cd70d765d6291f16325e5d start with left sonar and left motor * serial output will build from left to right --- diff --git a/build-stages/b_left_sonar/b_left_sonar.ino b/build-stages/b_left_sonar/b_left_sonar.ino new file mode 100644 index 0000000..4b648b2 --- /dev/null +++ b/build-stages/b_left_sonar/b_left_sonar.ino @@ -0,0 +1,52 @@ +/* + 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 . + */ +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);} diff --git a/build-stages/b_left_sonar/left-sonar.fzz b/build-stages/b_left_sonar/left-sonar.fzz new file mode 100644 index 0000000..b011301 Binary files /dev/null and b/build-stages/b_left_sonar/left-sonar.fzz differ diff --git a/build-stages/b_right_sonar/b_right_sonar.ino b/build-stages/b_right_sonar/b_right_sonar.ino deleted file mode 100644 index 3d4af2e..0000000 --- a/build-stages/b_right_sonar/b_right_sonar.ino +++ /dev/null @@ -1,52 +0,0 @@ -/* - 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 . - */ -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);} diff --git a/build-stages/b_right_sonar/right-sonar.fzz b/build-stages/b_right_sonar/right-sonar.fzz deleted file mode 100644 index 8fa1313..0000000 Binary files a/build-stages/b_right_sonar/right-sonar.fzz and /dev/null differ diff --git a/build-stages/c_both_sonars/c_both_sonars.ino b/build-stages/c_both_sonars/c_both_sonars.ino index 2d850ff..931e1b1 100644 --- a/build-stages/c_both_sonars/c_both_sonars.ino +++ b/build-stages/c_both_sonars/c_both_sonars.ino @@ -18,9 +18,6 @@ int right_trigger_pin = 7; 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){ @@ -47,6 +44,12 @@ 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 +58,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. diff --git a/build-stages/d_left_motor/d_left_motor.ino b/build-stages/d_left_motor/d_left_motor.ino new file mode 100644 index 0000000..e2d7a56 --- /dev/null +++ b/build-stages/d_left_motor/d_left_motor.ino @@ -0,0 +1,31 @@ +/* + 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 . + */ + +// 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);} diff --git a/build-stages/d_left_motor/left-motor.fzz b/build-stages/d_left_motor/left-motor.fzz new file mode 100644 index 0000000..57a8f00 Binary files /dev/null and b/build-stages/d_left_motor/left-motor.fzz differ diff --git a/build-stages/d_right_motor/d_right_motor.ino b/build-stages/d_right_motor/d_right_motor.ino deleted file mode 100644 index a27b984..0000000 --- a/build-stages/d_right_motor/d_right_motor.ino +++ /dev/null @@ -1,31 +0,0 @@ -/* - 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 . - */ - -// 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);} diff --git a/build-stages/d_right_motor/right-motor.fzz b/build-stages/d_right_motor/right-motor.fzz deleted file mode 100644 index b70b07e..0000000 Binary files a/build-stages/d_right_motor/right-motor.fzz and /dev/null differ