![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Sevro_drive
main.cpp
- Committer:
- ajp109
- Date:
- 2021-03-18
- Revision:
- 1:a7c3f3f3f2e7
- Parent:
- 0:77209603a6fe
- Child:
- 2:061e2fe8ae1a
File content as of revision 1:a7c3f3f3f2e7:
#include "mbed.h" // Initialise D2 as an OPEN DRAIN output // It can be used in the same way as a normal DigitalOut DigitalInOut trig(D2, PIN_OUTPUT, OpenDrain, 0); // Initialise D3 as an input DigitalIn echo(D3); int main() { while(true) { // Send 10us trigger pulse trig = true; wait_us(10); trig = false; while(!echo); // Wait for echo pulse to start while(echo); // Wait for echo pulse to end printf("Echo received\n"); thread_sleep_for(500); } }