So wisdom
/
Servo_for_f303re
Sevro_drive
Revision 2:061e2fe8ae1a, committed 2021-12-15
- Comitter:
- ajp109
- Date:
- Wed Dec 15 12:42:08 2021 +0000
- Parent:
- 1:a7c3f3f3f2e7
- Commit message:
- Initial commit of 2022 assessment
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a7c3f3f3f2e7 -r 061e2fe8ae1a main.cpp --- 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); + } } }