From 7958dc181855e051b6862c927fbd179184f2b0bf Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Tue, 30 Jun 2009 21:33:32 +0000 Subject: [PATCH] updated example to match tutorial style guide --- .../dist/examples/Sensors/Ping/Ping.pde | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/build/shared/dist/examples/Sensors/Ping/Ping.pde b/build/shared/dist/examples/Sensors/Ping/Ping.pde index 1a7f09c5c..3e8974429 100644 --- a/build/shared/dist/examples/Sensors/Ping/Ping.pde +++ b/build/shared/dist/examples/Sensors/Ping/Ping.pde @@ -1,16 +1,42 @@ -int pingPin = 7; +/* Ping))) Sensor + + This sketch reads a PING))) ultrasonic rangefinder and returns the + distance to the closest object in range. To do this, it sends a pulse + to the sensor to initiate a reading, then listens for a pulse + to return. The length of the returning pulse is proportional to + the distance of the object from the sensor. + + The circuit: + * +V connection of the PING))) attached to +5V + * GND connection of the PING))) attached to ground + * SIG connection of the PING))) attached to digital pin 7 -void setup() -{ + http://www.arduino.cc/en/Tutorial/Ping + + created 3 Nov 2008 + by David A. Mellis + modified 30 Jun 2009 + by Tom Igoe + + */ + +// this constant won't change. It's the pin number +// of the sensor's output: +const int pingPin = 7; + +void setup() { + // initialize serial communication: Serial.begin(9600); } void loop() { + // establish variables for duration of the ping, + // and the distance result in inches and centimeters: long duration, inches, cm; // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. - // We give a short LOW pulse beforehand to ensure a clean HIGH pulse. + // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2);