From 542a64fac1252343580d534ae990e3f870b37bd1 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 3 Nov 2008 20:18:37 +0000 Subject: [PATCH] Updating Ping example (to print distance rather than blink an LED). --- .../shared/dist/examples/Sensors/Ping/Ping.pde | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/build/shared/dist/examples/Sensors/Ping/Ping.pde b/build/shared/dist/examples/Sensors/Ping/Ping.pde index 9b2f38d70..1a7f09c5c 100644 --- a/build/shared/dist/examples/Sensors/Ping/Ping.pde +++ b/build/shared/dist/examples/Sensors/Ping/Ping.pde @@ -1,9 +1,8 @@ int pingPin = 7; -int ledPin = 13; void setup() { - pinMode(13, OUTPUT); + Serial.begin(9600); } void loop() @@ -28,12 +27,14 @@ void loop() // convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); - - // the closer an object is, the faster the led will blink - digitalWrite(ledPin, HIGH); - delay(cm); - digitalWrite(ledPin, LOW); - delay(cm); + + Serial.print(inches); + Serial.print("in, "); + Serial.print(cm); + Serial.print("cm"); + Serial.println(); + + delay(100); } long microsecondsToInches(long microseconds)