yes Spada / Mbed OS programme

main.cpp

Committer:
loicguibert
Date:
2019-02-28
Revision:
1:4010b3131918
Parent:
0:cbc40e6ff273
Child:
2:1dece5699c8b

File content as of revision 1:4010b3131918:

#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", deep_sleep_mode ? "true\r\n" : "false\r\n");
    
    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);
        }
        if (led1.read() == 0) {
            logger.log("LED state: 0.\r\n");
        } else {
            logger.log("LED state: 1.\r\n");
        }

    }
}