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@0:cbc40e6ff273, 2019-02-27 (annotated)
- Committer:
- loicguibert
- Date:
- Wed Feb 27 21:07:55 2019 +0000
- Revision:
- 0:cbc40e6ff273
- Child:
- 1:4010b3131918
TP01 1st version: logging capacity, switch mode capacity
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 | 0:cbc40e6ff273 | 7 | // Set the used LED |
loicguibert | 0:cbc40e6ff273 | 8 | DigitalOut led1(LED1); |
loicguibert | 0:cbc40e6ff273 | 9 | |
loicguibert | 0:cbc40e6ff273 | 10 | // Set the duration between the LED's blinking |
loicguibert | 0:cbc40e6ff273 | 11 | int wait_time = 1000; |
loicguibert | 0:cbc40e6ff273 | 12 | |
loicguibert | 0:cbc40e6ff273 | 13 | // Set the basic waiting mechanism |
loicguibert | 0:cbc40e6ff273 | 14 | BusyWaiter busy_waiter; |
loicguibert | 0:cbc40e6ff273 | 15 | |
loicguibert | 0:cbc40e6ff273 | 16 | // Set the logger handler |
loicguibert | 0:cbc40e6ff273 | 17 | Logger logger(true); |
loicguibert | 0:cbc40e6ff273 | 18 | |
loicguibert | 0:cbc40e6ff273 | 19 | int main () { |
loicguibert | 0:cbc40e6ff273 | 20 | Logger logger(false); |
loicguibert | 0:cbc40e6ff273 | 21 | |
loicguibert | 0:cbc40e6ff273 | 22 | // defining which waiting mechanism we want to use |
loicguibert | 0:cbc40e6ff273 | 23 | bool deep_sleep_mode = true; |
loicguibert | 0:cbc40e6ff273 | 24 | |
loicguibert | 0:cbc40e6ff273 | 25 | logger.log("Entering blinking state.\n"); |
loicguibert | 0:cbc40e6ff273 | 26 | |
loicguibert | 0:cbc40e6ff273 | 27 | while (true) { |
loicguibert | 0:cbc40e6ff273 | 28 | // Blink LED by inversing its state |
loicguibert | 0:cbc40e6ff273 | 29 | led1 = !led1; |
loicguibert | 0:cbc40e6ff273 | 30 | |
loicguibert | 0:cbc40e6ff273 | 31 | if (deep_sleep_mode) { |
loicguibert | 0:cbc40e6ff273 | 32 | /* As seen on the TP1's doc: |
loicguibert | 0:cbc40e6ff273 | 33 | * Using the ThisThread::sleep_for() method: this method allows the CPU to |
loicguibert | 0:cbc40e6ff273 | 34 | * enter deep sleep mode and thus to reduce power consumption between events. |
loicguibert | 0:cbc40e6ff273 | 35 | */ |
loicguibert | 0:cbc40e6ff273 | 36 | ThisThread::sleep_for(wait_time); |
loicguibert | 0:cbc40e6ff273 | 37 | } else { |
loicguibert | 0:cbc40e6ff273 | 38 | /* As seen on the TP1's doc: |
loicguibert | 0:cbc40e6ff273 | 39 | Using the BusyWaiter::wait() method - the class is provided to you and |
loicguibert | 0:cbc40e6ff273 | 40 | * you must include it into your project. |
loicguibert | 0:cbc40e6ff273 | 41 | */ |
loicguibert | 0:cbc40e6ff273 | 42 | busy_waiter.wait(wait_time); |
loicguibert | 0:cbc40e6ff273 | 43 | } |
loicguibert | 0:cbc40e6ff273 | 44 | if (led1.read() == 0) { |
loicguibert | 0:cbc40e6ff273 | 45 | logger.log("LED state: 0.\n"); |
loicguibert | 0:cbc40e6ff273 | 46 | } else { |
loicguibert | 0:cbc40e6ff273 | 47 | logger.log("LED state: 1.\n"); |
loicguibert | 0:cbc40e6ff273 | 48 | } |
loicguibert | 0:cbc40e6ff273 | 49 | |
loicguibert | 0:cbc40e6ff273 | 50 | } |
loicguibert | 0:cbc40e6ff273 | 51 | } |