Linear Servo MBED Control
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "Servo.h" 00003 #include "Timer.h" 00004 00005 DigitalIn pixhawk(LED1); 00006 Servo gas(p21); 00007 Servo brake(p22); 00008 Timer timer; 00009 float delta; 00010 00011 int main() 00012 { 00013 while(1) { 00014 // read pulseIn 00015 while (!pixhawk); // wait for high 1 or -1 00016 timer.reset(); 00017 timer.start(); 00018 while (pixhawk); // wait for low 00019 timer.stop(); 00020 delta = timer.read_us(); //provides pwm on time in microseconds 00021 00022 if(delta > 0) { 00023 gas = delta*1000; // convert to PWM signal for gas 00024 } else if(delta <= 0 && delta > 0.33) { 00025 brake = -.4; // light braking 00026 } else { 00027 brake = -1; // full brake 00028 } 00029 } 00030 }
Generated on Mon Oct 17 2022 03:18:09 by
1.7.2