yes Spada / Mbed OS programme
Committer:
loicguibert
Date:
Thu Feb 28 12:19:46 2019 +0000
Revision:
1:4010b3131918
Parent:
0:cbc40e6ff273
Child:
2:1dece5699c8b
First prog for the first "tp"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
loicguibert 0:cbc40e6ff273 1 #include "mbed.h"
loicguibert 0:cbc40e6ff273 2 #include "rtos.h"
loicguibert 0:cbc40e6ff273 3
loicguibert 0:cbc40e6ff273 4 #include "Logger.h"
loicguibert 0:cbc40e6ff273 5 #include "BusyWaiter.h"
loicguibert 0:cbc40e6ff273 6
loicguibert 1:4010b3131918 7
loicguibert 0:cbc40e6ff273 8 // Set the used LED
loicguibert 0:cbc40e6ff273 9 DigitalOut led1(LED1);
loicguibert 0:cbc40e6ff273 10
loicguibert 0:cbc40e6ff273 11 // Set the duration between the LED's blinking
loicguibert 0:cbc40e6ff273 12 int wait_time = 1000;
loicguibert 0:cbc40e6ff273 13
loicguibert 0:cbc40e6ff273 14 // Set the basic waiting mechanism
loicguibert 0:cbc40e6ff273 15 BusyWaiter busy_waiter;
loicguibert 0:cbc40e6ff273 16
loicguibert 0:cbc40e6ff273 17 // Set the logger handler
loicguibert 0:cbc40e6ff273 18 Logger logger(true);
loicguibert 0:cbc40e6ff273 19
loicguibert 1:4010b3131918 20
loicguibert 0:cbc40e6ff273 21 int main () {
loicguibert 1:4010b3131918 22
loicguibert 1:4010b3131918 23 // Waiting for the console connection
loicguibert 1:4010b3131918 24 busy_waiter.wait(2000);
loicguibert 1:4010b3131918 25
loicguibert 1:4010b3131918 26 logger.log("Code written by Loic Guibert.\r\n");
loicguibert 0:cbc40e6ff273 27
loicguibert 0:cbc40e6ff273 28 // defining which waiting mechanism we want to use
loicguibert 0:cbc40e6ff273 29 bool deep_sleep_mode = true;
loicguibert 0:cbc40e6ff273 30
loicguibert 1:4010b3131918 31 // Gives the mode
loicguibert 1:4010b3131918 32 logger.log("Entering blinking state. Deep Mode: %s", deep_sleep_mode ? "true\r\n" : "false\r\n");
loicguibert 0:cbc40e6ff273 33
loicguibert 0:cbc40e6ff273 34 while (true) {
loicguibert 0:cbc40e6ff273 35 // Blink LED by inversing its state
loicguibert 0:cbc40e6ff273 36 led1 = !led1;
loicguibert 0:cbc40e6ff273 37
loicguibert 0:cbc40e6ff273 38 if (deep_sleep_mode) {
loicguibert 0:cbc40e6ff273 39 /* As seen on the TP1's doc:
loicguibert 0:cbc40e6ff273 40 * Using the ThisThread::sleep_for() method: this method allows the CPU to
loicguibert 0:cbc40e6ff273 41 * enter deep sleep mode and thus to reduce power consumption between events.
loicguibert 0:cbc40e6ff273 42 */
loicguibert 0:cbc40e6ff273 43 ThisThread::sleep_for(wait_time);
loicguibert 0:cbc40e6ff273 44 } else {
loicguibert 0:cbc40e6ff273 45 /* As seen on the TP1's doc:
loicguibert 1:4010b3131918 46 Using the BusyWaiter::wait() method w- the class is provided to you and
loicguibert 0:cbc40e6ff273 47 * you must include it into your project.
loicguibert 0:cbc40e6ff273 48 */
loicguibert 0:cbc40e6ff273 49 busy_waiter.wait(wait_time);
loicguibert 0:cbc40e6ff273 50 }
loicguibert 0:cbc40e6ff273 51 if (led1.read() == 0) {
loicguibert 1:4010b3131918 52 logger.log("LED state: 0.\r\n");
loicguibert 0:cbc40e6ff273 53 } else {
loicguibert 1:4010b3131918 54 logger.log("LED state: 1.\r\n");
loicguibert 0:cbc40e6ff273 55 }
loicguibert 0:cbc40e6ff273 56
loicguibert 0:cbc40e6ff273 57 }
loicguibert 0:cbc40e6ff273 58 }