23 lines
640 B
C++
23 lines
640 B
C++
#include <Arduino.h>
|
|
#include "MeMCore.h"
|
|
|
|
// Define the Ultrasonic Sensor using Makeblock library
|
|
MeUltrasonicSensor ultrasonic(PORT_3); // Change PORT_3 to the actual port used
|
|
|
|
void setup() {
|
|
Serial.begin(9600); // Start serial communication
|
|
}
|
|
|
|
void loop() {
|
|
double distance_cm = ultrasonic.distanceCm(); // Get distance in cm
|
|
double distance_in = ultrasonic.distanceInch(); // Get distance in inches
|
|
|
|
Serial.print("Distance: ");
|
|
Serial.print(distance_cm);
|
|
Serial.print(" cm | ");
|
|
Serial.print(distance_in);
|
|
Serial.println(" inches");
|
|
|
|
delay(500); // Wait for 500ms before the next measurement
|
|
}
|