Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of Nucleo_UltrasonicHelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "ultrasonic.h" 00003 00004 Serial pc(USBTX, USBRX); // tx, rx 00005 00006 void dist(int distance) 00007 { 00008 //put code here to happen when the distance is changed 00009 pc.printf("Distance changed to %dmm\r\n", distance); 00010 //pc.printf("Distance changed!\n"); 00011 //printf("Distance changed!\r\n"); 00012 } 00013 00014 //ultrasonic mu(D8, D9, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 00015 //have updates every .1 seconds and a timeout after 1 00016 //second, and call dist when the distance changes 00017 00018 ultrasonic mu(p30, p29, .1, 1, &dist); //Set the trigger pin to D30 and the echo pin to D29 00019 //have updates every .1 seconds and a timeout after 1 00020 //second, and call dist when the distance changes 00021 00022 //Other sensors can be declared here. 00023 //ultrasonic nu(pwhatever, pwhatever, .1, 1, &distNu); 00024 //Then we can have multiple independent sensors that each are interrupt driven? 00025 //I'm worried that I don't understand enough about interrupts and counting that this will work. 00026 00027 int main() 00028 { 00029 mu.startUpdates();//start measuring the distance 00030 while(1) 00031 { 00032 //Do something else here 00033 mu.checkDistance(); //call checkDistance() as much as possible, as this is where 00034 //the class checks if dist needs to be called. 00035 } 00036 }
Generated on Sat Jul 16 2022 05:19:13 by
1.7.2
