mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-30 11:24:12 +01:00
Updating Ping example (to print distance rather than blink an LED).
This commit is contained in:
parent
f03a7d1f0e
commit
542a64fac1
17
build/shared/dist/examples/Sensors/Ping/Ping.pde
vendored
17
build/shared/dist/examples/Sensors/Ping/Ping.pde
vendored
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user