
Linear Servo MBED Control
Revision 0:33e05a8577f2, committed 2018-02-09
- Comitter:
- m182376
- Date:
- Fri Feb 09 02:00:48 2018 +0000
- Commit message:
- Linear Servo MBED Control
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Fri Feb 09 02:00:48 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 09 02:00:48 2018 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" +#include "Servo.h" +#include "Timer.h" + +DigitalIn pixhawk(LED1); +Servo gas(p21); +Servo brake(p22); +Timer timer; +float delta; + +int main() +{ + while(1) { + // read pulseIn + while (!pixhawk); // wait for high 1 or -1 + timer.reset(); + timer.start(); + while (pixhawk); // wait for low + timer.stop(); + delta = timer.read_us(); //provides pwm on time in microseconds + + if(delta > 0) { + gas = delta*1000; // convert to PWM signal for gas + } else if(delta <= 0 && delta > 0.33) { + brake = -.4; // light braking + } else { + brake = -1; // full brake + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Feb 09 02:00:48 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file