This commit is contained in:
parent
8f8b53e7ea
commit
13e19d80d2
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "MeMCore.h"
|
||||||
|
|
||||||
|
// Declare 1 variable of type MeUltrasonicSensor at PORT_3
|
||||||
|
MeUltrasonicSensor sensor(PORT_3);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize the serial port at 9600 baud
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Use the distanceCm() method to retrieve the distance of the obstacle
|
||||||
|
float distance = sensor.distanceCm( );
|
||||||
|
|
||||||
|
// Use the print() method of the Serial port to send the distance
|
||||||
|
Serial.print("Distance: ");
|
||||||
|
Serial.print(distance);
|
||||||
|
Serial.println(" cm");
|
||||||
|
|
||||||
|
// Add a small delay to avoid continuous printing
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue