Sevro_drive

Dependencies:   UoY-serial

Committer:
ajp109
Date:
Wed Dec 15 12:42:08 2021 +0000
Revision:
2:061e2fe8ae1a
Parent:
1:a7c3f3f3f2e7
Initial commit of 2022 assessment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ajp109 0:77209603a6fe 1 #include "mbed.h"
ajp109 0:77209603a6fe 2
ajp109 1:a7c3f3f3f2e7 3 // Initialise D2 as an OPEN DRAIN output
ajp109 1:a7c3f3f3f2e7 4 // It can be used in the same way as a normal DigitalOut
ajp109 2:061e2fe8ae1a 5 DigitalInOut sig(D2, PIN_OUTPUT, OpenDrain, 0);
ajp109 1:a7c3f3f3f2e7 6
ajp109 0:77209603a6fe 7 int main()
ajp109 0:77209603a6fe 8 {
ajp109 1:a7c3f3f3f2e7 9 while(true) {
ajp109 2:061e2fe8ae1a 10 for (int pulseWidth = 1000; pulseWidth < 2000; pulseWidth += 10) {
ajp109 2:061e2fe8ae1a 11 // Send servo pulse
ajp109 2:061e2fe8ae1a 12 sig = true;
ajp109 2:061e2fe8ae1a 13 wait_us(pulseWidth);
ajp109 2:061e2fe8ae1a 14 sig = false;
ajp109 2:061e2fe8ae1a 15
ajp109 2:061e2fe8ae1a 16 // Wait for approx. 20ms
ajp109 2:061e2fe8ae1a 17 thread_sleep_for(20);
ajp109 2:061e2fe8ae1a 18 }
ajp109 1:a7c3f3f3f2e7 19 }
ajp109 0:77209603a6fe 20 }