Pulsewideth-Changer

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 PwmOut servo(PA_9);
00004 DigitalOut myled(LED1);
00005 InterruptIn in(PA_10);
00006 
00007 double captime;
00008 Timer t;
00009 
00010 void flip_rise(){           //risng edge interrupt
00011     t.start();              //Timer Start
00012     flag = 0;
00013 }
00014     
00015 void flip_fall(){           //falling edge interrupt
00016     t.stop();               //Timer Stop
00017     captime = t.read_us();  //captime = pulse on time[us]
00018     t.reset();              //reset Timer
00019 }
00020 
00021 int main() {
00022     in.rise(&flip_rise);
00023     in.fall(&flip_fall);
00024     while(1) {
00025         printf("%f\n\r",captime);
00026         servo.pulsewidth_us((captime-1500)*3/2+1500);
00027     }
00028 }