mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Updating Ping example (to print distance rather than blink an LED).
This commit is contained in:
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 pingPin = 7;
|
||||||
int ledPin = 13;
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
pinMode(13, OUTPUT);
|
Serial.begin(9600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
@ -28,12 +27,14 @@ void loop()
|
|||||||
// convert the time into a distance
|
// convert the time into a distance
|
||||||
inches = microsecondsToInches(duration);
|
inches = microsecondsToInches(duration);
|
||||||
cm = microsecondsToCentimeters(duration);
|
cm = microsecondsToCentimeters(duration);
|
||||||
|
|
||||||
// the closer an object is, the faster the led will blink
|
Serial.print(inches);
|
||||||
digitalWrite(ledPin, HIGH);
|
Serial.print("in, ");
|
||||||
delay(cm);
|
Serial.print(cm);
|
||||||
digitalWrite(ledPin, LOW);
|
Serial.print("cm");
|
||||||
delay(cm);
|
Serial.println();
|
||||||
|
|
||||||
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
long microsecondsToInches(long microseconds)
|
long microsecondsToInches(long microseconds)
|
||||||
|
Reference in New Issue
Block a user