Skip to content

Instantly share code, notes, and snippets.

@katsuyoshi
Last active May 19, 2019 16:04
Show Gist options
  • Save katsuyoshi/13fabee26be6693f07465ee44c2a031a to your computer and use it in GitHub Desktop.
Save katsuyoshi/13fabee26be6693f07465ee44c2a031a to your computer and use it in GitHub Desktop.
Measure distance by Grove ultrasonic sensor using M5Stack.
#include <M5Stack.h>
#include <Ultrasonic.h>
const int USONIC_PIN = 2;
Ultrasonic ultrasonic(USONIC_PIN);
void setup() {
M5.begin();
M5.Lcd.setTextSize(2);
}
void loop() {
long distance = ultrasonic.MeasureInCentimeters();
M5.Lcd.printf("Distance %ld cm\n", distance);
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment