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.
Dependencies: Hotboards_leds mbed
main.cpp@0:a0ed46c36cdc, 2016-02-29 (annotated)
- Committer:
- RomanValenciaP
- Date:
- Mon Feb 29 20:03:19 2016 +0000
- Revision:
- 0:a0ed46c36cdc
first release - requires approval
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RomanValenciaP | 0:a0ed46c36cdc | 1 | |
| RomanValenciaP | 0:a0ed46c36cdc | 2 | /* |
| RomanValenciaP | 0:a0ed46c36cdc | 3 | * This program blinks a led but this time we will show you |
| RomanValenciaP | 0:a0ed46c36cdc | 4 | * how to use the write function to manipulate the led state |
| RomanValenciaP | 0:a0ed46c36cdc | 5 | * according to a variable value |
| RomanValenciaP | 0:a0ed46c36cdc | 6 | * |
| RomanValenciaP | 0:a0ed46c36cdc | 7 | */ |
| RomanValenciaP | 0:a0ed46c36cdc | 8 | |
| RomanValenciaP | 0:a0ed46c36cdc | 9 | #include "mbed.h" |
| RomanValenciaP | 0:a0ed46c36cdc | 10 | #include "Hotboards_leds.h" |
| RomanValenciaP | 0:a0ed46c36cdc | 11 | |
| RomanValenciaP | 0:a0ed46c36cdc | 12 | //bitRead macro taken from arduino |
| RomanValenciaP | 0:a0ed46c36cdc | 13 | #define bitRead( var, bit ) (((var) >> (bit)) & 0x01) |
| RomanValenciaP | 0:a0ed46c36cdc | 14 | |
| RomanValenciaP | 0:a0ed46c36cdc | 15 | Hotboards_leds led( PA_5 ); |
| RomanValenciaP | 0:a0ed46c36cdc | 16 | |
| RomanValenciaP | 0:a0ed46c36cdc | 17 | uint8_t counter; |
| RomanValenciaP | 0:a0ed46c36cdc | 18 | |
| RomanValenciaP | 0:a0ed46c36cdc | 19 | int main() |
| RomanValenciaP | 0:a0ed46c36cdc | 20 | { |
| RomanValenciaP | 0:a0ed46c36cdc | 21 | while(1) |
| RomanValenciaP | 0:a0ed46c36cdc | 22 | { |
| RomanValenciaP | 0:a0ed46c36cdc | 23 | //The led will blink because we are writing the LSB |
| RomanValenciaP | 0:a0ed46c36cdc | 24 | //of the variable counter which on each iteration |
| RomanValenciaP | 0:a0ed46c36cdc | 25 | //is incremented by 1. |
| RomanValenciaP | 0:a0ed46c36cdc | 26 | led.write( bitRead( counter , 0 ) ); |
| RomanValenciaP | 0:a0ed46c36cdc | 27 | wait_ms( 200 ); |
| RomanValenciaP | 0:a0ed46c36cdc | 28 | counter ++; |
| RomanValenciaP | 0:a0ed46c36cdc | 29 | } |
| RomanValenciaP | 0:a0ed46c36cdc | 30 | } |