Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@2:1dece5699c8b, 2019-03-04 (annotated)
- Committer:
- loicguibert
- Date:
- Mon Mar 04 14:47:10 2019 +0000
- Revision:
- 2:1dece5699c8b
- Parent:
- 1:4010b3131918
- Child:
- 4:bfe306335065
Logging messages improved, code for tp.01 done.
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:1dece5699c8b | 32 | logger.log("Entering blinking state. Deep Mode: %s.\r\n", deep_sleep_mode ? "true" : "false"); |
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 | 2:1dece5699c8b | 51 | |
loicguibert | 2:1dece5699c8b | 52 | logger.log("LED state: %01d.\r\n", led1.read()); |
loicguibert | 0:cbc40e6ff273 | 53 | |
loicguibert | 0:cbc40e6ff273 | 54 | } |
loicguibert | 0:cbc40e6ff273 | 55 | } |