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:9ac802a0d2d9, 2018-09-11 (annotated)
- Committer:
- Mirjam
- Date:
- Tue Sep 11 15:02:25 2018 +0000
- Revision:
- 0:9ac802a0d2d9
- Child:
- 1:b483225a5411
First commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Mirjam | 0:9ac802a0d2d9 | 1 | #include "mbed.h" |
| Mirjam | 0:9ac802a0d2d9 | 2 | #include "MODSERIAL.h" |
| Mirjam | 0:9ac802a0d2d9 | 3 | // Make a BlinkLEd function using Ticker |
| Mirjam | 0:9ac802a0d2d9 | 4 | //Wait for a character to arrive pc.getc() in the main loop, |
| Mirjam | 0:9ac802a0d2d9 | 5 | //if character == ‘r’ blink red LED |
| Mirjam | 0:9ac802a0d2d9 | 6 | //if character == ‘b’ blink blue LED |
| Mirjam | 0:9ac802a0d2d9 | 7 | //if character == ‘g’ blink green LED |
| Mirjam | 0:9ac802a0d2d9 | 8 | |
| Mirjam | 0:9ac802a0d2d9 | 9 | Ticker blink; //Maak ticker aan |
| Mirjam | 0:9ac802a0d2d9 | 10 | |
| Mirjam | 0:9ac802a0d2d9 | 11 | enum states {r,b,g}; //Define possible states |
| Mirjam | 0:9ac802a0d2d9 | 12 | states currentState; //Make variable currentState |
| Mirjam | 0:9ac802a0d2d9 | 13 | |
| Mirjam | 0:9ac802a0d2d9 | 14 | DigitalOut ledr(LED_RED); |
| Mirjam | 0:9ac802a0d2d9 | 15 | DigitalOut ledb(LED_BLUE); |
| Mirjam | 0:9ac802a0d2d9 | 16 | DigitalOut ledg(LED_GREEN); |
| Mirjam | 0:9ac802a0d2d9 | 17 | |
| Mirjam | 0:9ac802a0d2d9 | 18 | void BlinkLed(void) |
| Mirjam | 0:9ac802a0d2d9 | 19 | { |
| Mirjam | 0:9ac802a0d2d9 | 20 | switch (currentState) |
| Mirjam | 0:9ac802a0d2d9 | 21 | { |
| Mirjam | 0:9ac802a0d2d9 | 22 | case r: //If the input character is r |
| Mirjam | 0:9ac802a0d2d9 | 23 | ledr = !ledr; |
| Mirjam | 0:9ac802a0d2d9 | 24 | break; |
| Mirjam | 0:9ac802a0d2d9 | 25 | |
| Mirjam | 0:9ac802a0d2d9 | 26 | case b: //If the input character is b |
| Mirjam | 0:9ac802a0d2d9 | 27 | ledb = !ledb; |
| Mirjam | 0:9ac802a0d2d9 | 28 | break; |
| Mirjam | 0:9ac802a0d2d9 | 29 | |
| Mirjam | 0:9ac802a0d2d9 | 30 | case g: //If the input character is g |
| Mirjam | 0:9ac802a0d2d9 | 31 | ledg= !ledg; |
| Mirjam | 0:9ac802a0d2d9 | 32 | break; |
| Mirjam | 0:9ac802a0d2d9 | 33 | |
| Mirjam | 0:9ac802a0d2d9 | 34 | default: |
| Mirjam | 0:9ac802a0d2d9 | 35 | // pc.print("There is no input"); |
| Mirjam | 0:9ac802a0d2d9 | 36 | break; |
| Mirjam | 0:9ac802a0d2d9 | 37 | } // End of switch |
| Mirjam | 0:9ac802a0d2d9 | 38 | |
| Mirjam | 0:9ac802a0d2d9 | 39 | |
| Mirjam | 0:9ac802a0d2d9 | 40 | int main() |
| Mirjam | 0:9ac802a0d2d9 | 41 | { |
| Mirjam | 0:9ac802a0d2d9 | 42 | blink.attach(BlinkLed,1); //Gaat elke seconde checken |
| Mirjam | 0:9ac802a0d2d9 | 43 | pc.baud(115200); //Instelling voor pc |
| Mirjam | 0:9ac802a0d2d9 | 44 | |
| Mirjam | 0:9ac802a0d2d9 | 45 | char c; // Maak character c aan |
| Mirjam | 0:9ac802a0d2d9 | 46 | c = pc.getc(); // Maak die gelijk aan ingevoerde character |
| Mirjam | 0:9ac802a0d2d9 | 47 | |
| Mirjam | 0:9ac802a0d2d9 | 48 | while (true) { |
| Mirjam | 0:9ac802a0d2d9 | 49 | currentState = c; |
| Mirjam | 0:9ac802a0d2d9 | 50 | BlinkLed(); |
| Mirjam | 0:9ac802a0d2d9 | 51 | } |
| Mirjam | 0:9ac802a0d2d9 | 52 | } |