Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
| ||||||
#include "mbed.h"
#include <HCSR04.h>
#define TRIGGER_PIN A1
#define ECHO_PIN A0
HCSR04 DistanceSensor(TRIGGER_PIN, ECHO_PIN);
Serial pc(USBTX, USBRX);
int main() {
pc.baud(115200);
int cm = DistanceSensor.distance(CM);
pc.printf("Distance: ");
pc.printf("%d",cm);
pc.printf("cm\n");
}









Comments