projects
/
challenge-bot
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6405fee
)
add LEDs to visually indicate distance sensed
author
daniel watson
<ozzloy@gmail.com>
Thu, 26 Jan 2017 01:57:55 +0000
(17:57 -0800)
committer
daniel watson
<ozzloy@gmail.com>
Thu, 26 Jan 2017 01:57:55 +0000
(17:57 -0800)
build-stages/g_follow/g_follow.ino
patch
|
blob
|
blame
|
history
diff --git
a/build-stages/g_follow/g_follow.ino
b/build-stages/g_follow/g_follow.ino
index f0ba76c8cbf3869697c86a68671b4898706e8bd7..02f6d96e688e0d5bff610228d1d9e490e5b1af42 100644
(file)
--- a/
build-stages/g_follow/g_follow.ino
+++ b/
build-stages/g_follow/g_follow.ino
@@
-13,9
+13,12
@@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+// right side LED, white wire
+int right_led_pin = 3;
+
// define which pins are connected to which components
// blue wire
// define which pins are connected to which components
// blue wire
-int right_motor_forward_pin =
3
;
+int right_motor_forward_pin =
2
;
// orange wire
int right_motor_backward_pin = 4;
// white wire
// orange wire
int right_motor_backward_pin = 4;
// white wire
@@
-26,11
+29,10
@@
int right_echo_pin = 6;
// blue wire
int right_trigger_pin = 7;
// blue wire
int right_trigger_pin = 7;
-
// blue wire
int left_motor_forward_pin = 8;
// orange wire
// blue wire
int left_motor_forward_pin = 8;
// orange wire
-int left_motor_backward_pin =
9
;
+int left_motor_backward_pin =
13
;
// white wire
int left_motor_speed_pin = 10;
// white wire
int left_motor_speed_pin = 10;
@@
-39,6
+41,9
@@
int left_echo_pin = 11;
// blue wire
int left_trigger_pin = 12;
// blue wire
int left_trigger_pin = 12;
+// left side LED, blue wire
+int left_led_pin = 9;
+
void on(int pin){
digitalWrite(pin, HIGH);}
void on(int pin){
digitalWrite(pin, HIGH);}
@@
-130,10
+135,21
@@
void loop() {
unsigned int actual_left_ping_time = ping(left_trigger_pin, left_echo_pin);
unsigned int actual_right_ping_time = ping(right_trigger_pin, right_echo_pin);
unsigned int actual_left_ping_time = ping(left_trigger_pin, left_echo_pin);
unsigned int actual_right_ping_time = ping(right_trigger_pin, right_echo_pin);
+ int left_led_value = (int)(actual_left_ping_time / 16.0);
+ int right_led_value = (int)(actual_right_ping_time / 16.0);
+
+ Serial.print("left led value = ");
+ Serial.print(left_led_value);
+ Serial.print(", right led value = ");
+ Serial.print(right_led_value);
+
+ analogWrite(left_led_pin, left_led_value);
+ analogWrite(right_led_pin, right_led_value);
+
left_speed = actual_left_ping_time - desired_left_ping_time;
right_speed = actual_right_ping_time - desired_right_ping_time;
left_speed = actual_left_ping_time - desired_left_ping_time;
right_speed = actual_right_ping_time - desired_right_ping_time;
- Serial.print("left: ping = ");
+ Serial.print("
,
left: ping = ");
Serial.print(actual_left_ping_time);
Serial.print(" speed = ");
Serial.print(left_speed);
Serial.print(actual_left_ping_time);
Serial.print(" speed = ");
Serial.print(left_speed);