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:fe8a2e63737f, 2017-12-15 (annotated)
- Committer:
- ygendrault
- Date:
- Fri Dec 15 15:04:47 2017 +0000
- Revision:
- 0:fe8a2e63737f
On/Off on the embedded LED on Nucleo for ECAM S-E student
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ygendrault | 0:fe8a2e63737f | 1 | #include "mbed.h" |
ygendrault | 0:fe8a2e63737f | 2 | |
ygendrault | 0:fe8a2e63737f | 3 | Serial pc(SERIAL_TX, SERIAL_RX); |
ygendrault | 0:fe8a2e63737f | 4 | DigitalOut led(LED1); |
ygendrault | 0:fe8a2e63737f | 5 | int test = 0; |
ygendrault | 0:fe8a2e63737f | 6 | char previous = 0; |
ygendrault | 0:fe8a2e63737f | 7 | |
ygendrault | 0:fe8a2e63737f | 8 | int main() |
ygendrault | 0:fe8a2e63737f | 9 | { |
ygendrault | 0:fe8a2e63737f | 10 | pc.printf("Press '1' to turn LED1 ON, '0' to turn it OFF\n"); |
ygendrault | 0:fe8a2e63737f | 11 | while(1) { |
ygendrault | 0:fe8a2e63737f | 12 | char c = pc.getc(); // Read hyperterminal |
ygendrault | 0:fe8a2e63737f | 13 | if (c == '0') { |
ygendrault | 0:fe8a2e63737f | 14 | if (previous=='1') |
ygendrault | 0:fe8a2e63737f | 15 | { |
ygendrault | 0:fe8a2e63737f | 16 | test =0; |
ygendrault | 0:fe8a2e63737f | 17 | } |
ygendrault | 0:fe8a2e63737f | 18 | if (test==0) |
ygendrault | 0:fe8a2e63737f | 19 | { |
ygendrault | 0:fe8a2e63737f | 20 | test=1; |
ygendrault | 0:fe8a2e63737f | 21 | previous = '0'; |
ygendrault | 0:fe8a2e63737f | 22 | led = 0; // OFF |
ygendrault | 0:fe8a2e63737f | 23 | } |
ygendrault | 0:fe8a2e63737f | 24 | else |
ygendrault | 0:fe8a2e63737f | 25 | { |
ygendrault | 0:fe8a2e63737f | 26 | pc.printf("LED already OFF\n"); |
ygendrault | 0:fe8a2e63737f | 27 | } |
ygendrault | 0:fe8a2e63737f | 28 | } |
ygendrault | 0:fe8a2e63737f | 29 | if (c == '1') { |
ygendrault | 0:fe8a2e63737f | 30 | if (previous=='0') |
ygendrault | 0:fe8a2e63737f | 31 | { |
ygendrault | 0:fe8a2e63737f | 32 | test =0; |
ygendrault | 0:fe8a2e63737f | 33 | } |
ygendrault | 0:fe8a2e63737f | 34 | if (test==0) |
ygendrault | 0:fe8a2e63737f | 35 | { |
ygendrault | 0:fe8a2e63737f | 36 | test=1; |
ygendrault | 0:fe8a2e63737f | 37 | previous = '1'; |
ygendrault | 0:fe8a2e63737f | 38 | led = 1; // OFF |
ygendrault | 0:fe8a2e63737f | 39 | } |
ygendrault | 0:fe8a2e63737f | 40 | else |
ygendrault | 0:fe8a2e63737f | 41 | { |
ygendrault | 0:fe8a2e63737f | 42 | pc.printf("LED already ON\n"); |
ygendrault | 0:fe8a2e63737f | 43 | } |
ygendrault | 0:fe8a2e63737f | 44 | } |
ygendrault | 0:fe8a2e63737f | 45 | } |
ygendrault | 0:fe8a2e63737f | 46 | } |