Purpose: Simple application example with 3 periodic functions triggered through a event-queue scheduler-object.

Dependencies:   IHM_V2

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Title : mbed-os-periodic-task
00002 // Author: Jacques-Olivier Klein - IUT de CACHAN
00003 // Date: 2018-02-10 rev. 2019-01-06
00004 
00005 #include "mbed.h"
00006 #include "IHM.h"
00007 
00008 IHM ihm; 
00009 
00010 DigitalOut L0 (PB_3) ;  // led L0
00011 DigitalOut L1 (PA_7) ;  // led L1
00012 DigitalOut L2 (PA_6) ;  // led L2
00013 DigitalOut L6 (PA_0) ;  // led L6
00014 
00015 void led0_fun();
00016 void led1_fun();
00017 void led2_fun();
00018 
00019 EventQueue the_event_queue;
00020 
00021 int main(void)
00022 {   ihm.LCD_clear();
00023     ihm.LCD_printf("periodic-task-%s %s",__DATE__,__TIME__);
00024     printf("mbed-os-periodic-task-%s %s\n\r",__DATE__,__TIME__);
00025     printf("OS_STACK_SIZE:%d\n\r", OS_STACK_SIZE); 
00026 
00027     the_event_queue.call_every(100, led0_fun);
00028     the_event_queue.call_every(400, led1_fun);
00029     the_event_queue.call_every(1600, led2_fun);
00030     
00031     printf("Starting event_queue...\n\r");   
00032     the_event_queue.dispatch();
00033    
00034     //while(1) hereafter will never be executed    
00035     while(1){
00036         wait(0.500);  
00037         L6=!L6;
00038     }
00039 }
00040 
00041 void led0_fun()
00042 {
00043    L0 = ! L0;
00044 }
00045 
00046 void led1_fun()
00047 {
00048    L1 = ! L1;
00049 }
00050 
00051 void led2_fun()
00052 {
00053    L2 = ! L2;
00054 }