mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
updated example to match tutorial style guide
This commit is contained in:
parent
7a80165286
commit
7958dc1818
34
build/shared/dist/examples/Sensors/Ping/Ping.pde
vendored
34
build/shared/dist/examples/Sensors/Ping/Ping.pde
vendored
@ -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);
|
Serial.begin(9600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
// establish variables for duration of the ping,
|
||||||
|
// and the distance result in inches and centimeters:
|
||||||
long duration, inches, cm;
|
long duration, inches, cm;
|
||||||
|
|
||||||
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
|
// 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);
|
pinMode(pingPin, OUTPUT);
|
||||||
digitalWrite(pingPin, LOW);
|
digitalWrite(pingPin, LOW);
|
||||||
delayMicroseconds(2);
|
delayMicroseconds(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user