Cooper Liu / Mbed 2 deprecated Eurobot2013_IR

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "PwmIn.h"
00003 #include "globals.h"
00004 #include "rtos.h"
00005 
00006 #define PWM_INVERT
00007 
00008 DigitalOut led1(LED1);
00009 DigitalOut led2(LED2);
00010 Serial pc(USBTX, USBRX); // tx, rx
00011 
00012 PwmIn My_PWM(p30);
00013 float my_dutycycle;
00014 Semaphore serial_sema(1);
00015 
00016 void PWM_Callback(float dutycycle) {
00017     led1 = !led1;
00018     my_dutycycle = dutycycle;
00019     serial_sema.release();
00020     
00021 }
00022 
00023 
00024 void serial_thread(void const *argument) {
00025     while (true) {
00026         serial_sema.wait();
00027         printf("dutycycle: %0.4f \n\r", my_dutycycle);
00028     }
00029 }
00030  
00031 int main() {
00032     pc.baud(19200);
00033     pc.printf("Hello from mbed\n");    
00034     
00035     My_PWM.callbackfunc = PWM_Callback;
00036 
00037     Thread thread(serial_thread);
00038     
00039     while (true) {
00040         Thread::wait(osWaitForever);
00041     }
00042 }