yes Spada / Mbed OS programme

main.cpp

Committer:
loicguibert
Date:
2019-03-04
Revision:
2:1dece5699c8b
Parent:
1:4010b3131918
Child:
4:bfe306335065

File content as of revision 2:1dece5699c8b:

#include "mbed.h"
#include "rtos.h"

#include "Logger.h"
#include "BusyWaiter.h"


//  Set the used LED
DigitalOut led1(LED1);

//  Set the duration between the LED's blinking
int wait_time = 1000;

//  Set the basic waiting mechanism
BusyWaiter busy_waiter;

//  Set the logger handler
Logger logger(true);


int main () {
    
    //  Waiting for the console connection
    busy_waiter.wait(2000);
    
    logger.log("Code written by Loic Guibert.\r\n");
    
    //  defining which waiting mechanism we want to use
    bool deep_sleep_mode = true;
    
    //  Gives the mode
    logger.log("Entering blinking state. Deep Mode: %s.\r\n", deep_sleep_mode ? "true" : "false");
    
    while (true) {
        //  Blink LED by inversing its state
        led1 = !led1;

        if (deep_sleep_mode) {
            /*  As seen on the TP1's doc:
             *  Using the ThisThread::sleep_for() method: this method allows the CPU to 
             *  enter deep sleep mode and thus to reduce power consumption between events.
             */
            ThisThread::sleep_for(wait_time);
        } else {
            /*  As seen on the TP1's doc:
                Using the BusyWaiter::wait() method w- the class is provided to you and
             *  you must include it into your project.
             */
            busy_waiter.wait(wait_time);
        }
    
        logger.log("LED state: %01d.\r\n", led1.read());

    }
}