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: NeoStrip SerialDriver mbed-rtos mbed
main.cpp@0:0513e7187b87, 2016-01-30 (annotated)
- Committer:
- rossng
- Date:
- Sat Jan 30 20:10:17 2016 +0000
- Revision:
- 0:0513e7187b87
- Child:
- 1:6feb61c0e4a1
Initial version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rossng | 0:0513e7187b87 | 1 | #include "mbed.h" |
| rossng | 0:0513e7187b87 | 2 | #include "SerialDriver.h" |
| rossng | 0:0513e7187b87 | 3 | |
| rossng | 0:0513e7187b87 | 4 | SerialDriver pc(p9, p10); |
| rossng | 0:0513e7187b87 | 5 | DigitalOut myled(LED1); |
| rossng | 0:0513e7187b87 | 6 | |
| rossng | 0:0513e7187b87 | 7 | int flash(); |
| rossng | 0:0513e7187b87 | 8 | |
| rossng | 0:0513e7187b87 | 9 | int main() |
| rossng | 0:0513e7187b87 | 10 | { |
| rossng | 0:0513e7187b87 | 11 | // setup serial port |
| rossng | 0:0513e7187b87 | 12 | pc.baud(115200); |
| rossng | 0:0513e7187b87 | 13 | |
| rossng | 0:0513e7187b87 | 14 | char* line_buffer = (char*) malloc(100*sizeof(char)); |
| rossng | 0:0513e7187b87 | 15 | |
| rossng | 0:0513e7187b87 | 16 | char c = pc.getc(); |
| rossng | 0:0513e7187b87 | 17 | int pos = 0; |
| rossng | 0:0513e7187b87 | 18 | |
| rossng | 0:0513e7187b87 | 19 | while (c != '\n' && c != '\r') { |
| rossng | 0:0513e7187b87 | 20 | line_buffer[pos] = c; |
| rossng | 0:0513e7187b87 | 21 | c = pc.getc(); |
| rossng | 0:0513e7187b87 | 22 | } |
| rossng | 0:0513e7187b87 | 23 | |
| rossng | 0:0513e7187b87 | 24 | pc.printf("ack\n"); |
| rossng | 0:0513e7187b87 | 25 | |
| rossng | 0:0513e7187b87 | 26 | int result = strcmp(line_buffer, "hello"); |
| rossng | 0:0513e7187b87 | 27 | |
| rossng | 0:0513e7187b87 | 28 | if (result == 0) { |
| rossng | 0:0513e7187b87 | 29 | flash(); |
| rossng | 0:0513e7187b87 | 30 | } |
| rossng | 0:0513e7187b87 | 31 | } |
| rossng | 0:0513e7187b87 | 32 | |
| rossng | 0:0513e7187b87 | 33 | |
| rossng | 0:0513e7187b87 | 34 | int flash() { |
| rossng | 0:0513e7187b87 | 35 | while(1) { |
| rossng | 0:0513e7187b87 | 36 | myled = 1; |
| rossng | 0:0513e7187b87 | 37 | wait(0.2); |
| rossng | 0:0513e7187b87 | 38 | myled = 0; |
| rossng | 0:0513e7187b87 | 39 | wait(0.2); |
| rossng | 0:0513e7187b87 | 40 | } |
| rossng | 0:0513e7187b87 | 41 | } |