diff --git a/ultrasonicSensor/ultrasonicSensor/ultrasonicSensor.ino b/ultrasonicSensor/ultrasonicSensor/ultrasonicSensor.ino new file mode 100644 index 0000000..e93bbc9 --- /dev/null +++ b/ultrasonicSensor/ultrasonicSensor/ultrasonicSensor.ino @@ -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); +}