![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Sevro_drive
Diff: main.cpp
- Revision:
- 2:061e2fe8ae1a
- Parent:
- 1:a7c3f3f3f2e7
--- a/main.cpp Thu Mar 18 10:41:40 2021 +0000 +++ b/main.cpp Wed Dec 15 12:42:08 2021 +0000 @@ -2,22 +2,19 @@ // 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); +DigitalInOut sig(D2, PIN_OUTPUT, OpenDrain, 0); 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); + for (int pulseWidth = 1000; pulseWidth < 2000; pulseWidth += 10) { + // Send servo pulse + sig = true; + wait_us(pulseWidth); + sig = false; + + // Wait for approx. 20ms + thread_sleep_for(20); + } } }