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@2:51248529975d, 2018-09-11 (annotated)
- Committer:
- Mirjam
- Date:
- Tue Sep 11 15:24:39 2018 +0000
- Revision:
- 2:51248529975d
- Parent:
- 1:b483225a5411
- Child:
- 3:3cc8759a826f
Fix while loop. And one colour switched on at the time.
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 | 1:b483225a5411 | 3 | MODSERIAL pc(USBTX, USBRX);\ |
| Mirjam | 1:b483225a5411 | 4 | |
| Mirjam | 0:9ac802a0d2d9 | 5 | // Make a BlinkLEd function using Ticker |
| Mirjam | 0:9ac802a0d2d9 | 6 | //Wait for a character to arrive pc.getc() in the main loop, |
| Mirjam | 0:9ac802a0d2d9 | 7 | //if character == ‘r’ blink red LED |
| Mirjam | 0:9ac802a0d2d9 | 8 | //if character == ‘b’ blink blue LED |
| Mirjam | 0:9ac802a0d2d9 | 9 | //if character == ‘g’ blink green LED |
| Mirjam | 0:9ac802a0d2d9 | 10 | |
| Mirjam | 1:b483225a5411 | 11 | |
| Mirjam | 0:9ac802a0d2d9 | 12 | Ticker blink; //Maak ticker aan |
| Mirjam | 0:9ac802a0d2d9 | 13 | |
| Mirjam | 1:b483225a5411 | 14 | //enum states {r,b,g}; //Define possible states |
| Mirjam | 1:b483225a5411 | 15 | char currentState; //Make variable currentState |
| Mirjam | 0:9ac802a0d2d9 | 16 | |
| Mirjam | 0:9ac802a0d2d9 | 17 | DigitalOut ledr(LED_RED); |
| Mirjam | 0:9ac802a0d2d9 | 18 | DigitalOut ledb(LED_BLUE); |
| Mirjam | 0:9ac802a0d2d9 | 19 | DigitalOut ledg(LED_GREEN); |
| Mirjam | 0:9ac802a0d2d9 | 20 | |
| Mirjam | 0:9ac802a0d2d9 | 21 | void BlinkLed(void) |
| Mirjam | 0:9ac802a0d2d9 | 22 | { |
| Mirjam | 0:9ac802a0d2d9 | 23 | switch (currentState) |
| Mirjam | 0:9ac802a0d2d9 | 24 | { |
| Mirjam | 1:b483225a5411 | 25 | case 'r': //If the input character is r |
| Mirjam | 0:9ac802a0d2d9 | 26 | ledr = !ledr; |
| Mirjam | 2:51248529975d | 27 | ledb=1; |
| Mirjam | 2:51248529975d | 28 | ledg=1; |
| Mirjam | 0:9ac802a0d2d9 | 29 | break; |
| Mirjam | 0:9ac802a0d2d9 | 30 | |
| Mirjam | 1:b483225a5411 | 31 | case 'b': //If the input character is b |
| Mirjam | 0:9ac802a0d2d9 | 32 | ledb = !ledb; |
| Mirjam | 2:51248529975d | 33 | ledr=1; |
| Mirjam | 2:51248529975d | 34 | ledg=1; |
| Mirjam | 0:9ac802a0d2d9 | 35 | break; |
| Mirjam | 0:9ac802a0d2d9 | 36 | |
| Mirjam | 1:b483225a5411 | 37 | case 'g': //If the input character is g |
| Mirjam | 0:9ac802a0d2d9 | 38 | ledg= !ledg; |
| Mirjam | 2:51248529975d | 39 | ledb=1; |
| Mirjam | 2:51248529975d | 40 | ledr=1; |
| Mirjam | 0:9ac802a0d2d9 | 41 | break; |
| Mirjam | 0:9ac802a0d2d9 | 42 | |
| Mirjam | 0:9ac802a0d2d9 | 43 | default: |
| Mirjam | 0:9ac802a0d2d9 | 44 | // pc.print("There is no input"); |
| Mirjam | 0:9ac802a0d2d9 | 45 | break; |
| Mirjam | 0:9ac802a0d2d9 | 46 | } // End of switch |
| Mirjam | 1:b483225a5411 | 47 | } |
| Mirjam | 0:9ac802a0d2d9 | 48 | |
| Mirjam | 0:9ac802a0d2d9 | 49 | int main() |
| Mirjam | 0:9ac802a0d2d9 | 50 | { |
| Mirjam | 0:9ac802a0d2d9 | 51 | blink.attach(BlinkLed,1); //Gaat elke seconde checken |
| Mirjam | 0:9ac802a0d2d9 | 52 | pc.baud(115200); //Instelling voor pc |
| Mirjam | 2:51248529975d | 53 | |
| Mirjam | 0:9ac802a0d2d9 | 54 | while (true) { |
| Mirjam | 2:51248529975d | 55 | currentState = pc.getc(); |
| Mirjam | 0:9ac802a0d2d9 | 56 | } |
| Mirjam | 0:9ac802a0d2d9 | 57 | } |