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.
Fork of frdm_gpio by
main.cpp@10:163208bd16a8, 2015-07-20 (annotated)
- Committer:
- cheperuiz
- Date:
- Mon Jul 20 02:39:08 2015 +0000
- Revision:
- 10:163208bd16a8
- Parent:
- 9:32e85f1fcd15
Day 1!; Single button, color by received state & ID
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chris | 0:0024ab6b9624 | 1 | #include "mbed.h" |
| cheperuiz | 10:163208bd16a8 | 2 | #define ON 0 |
| cheperuiz | 10:163208bd16a8 | 3 | #define OFF 1 |
| cheperuiz | 10:163208bd16a8 | 4 | #define ID '0' |
| chris | 0:0024ab6b9624 | 5 | |
| cheperuiz | 10:163208bd16a8 | 6 | DigitalIn magic(PTB0); |
| cheperuiz | 10:163208bd16a8 | 7 | DigitalOut redLED(LED_RED); |
| cheperuiz | 10:163208bd16a8 | 8 | DigitalOut greenLED(LED_GREEN); |
| cheperuiz | 10:163208bd16a8 | 9 | DigitalOut blueLED(LED_BLUE); |
| cheperuiz | 10:163208bd16a8 | 10 | Serial pc(USBTX,USBRX); |
| chris | 0:0024ab6b9624 | 11 | |
| sam_grove | 9:32e85f1fcd15 | 12 | int main() |
| sam_grove | 9:32e85f1fcd15 | 13 | { |
| cheperuiz | 10:163208bd16a8 | 14 | unsigned char last = magic,t=0; |
| cheperuiz | 10:163208bd16a8 | 15 | while(true) |
| cheperuiz | 10:163208bd16a8 | 16 | { |
| cheperuiz | 10:163208bd16a8 | 17 | if(last != magic) |
| cheperuiz | 10:163208bd16a8 | 18 | { |
| cheperuiz | 10:163208bd16a8 | 19 | last = magic; |
| cheperuiz | 10:163208bd16a8 | 20 | printf("%d",(int)magic); |
| cheperuiz | 10:163208bd16a8 | 21 | // wait(0.02); |
| cheperuiz | 10:163208bd16a8 | 22 | } |
| cheperuiz | 10:163208bd16a8 | 23 | if(pc.readable()) |
| cheperuiz | 10:163208bd16a8 | 24 | { |
| cheperuiz | 10:163208bd16a8 | 25 | t=pc.getc(); |
| cheperuiz | 10:163208bd16a8 | 26 | switch(t) |
| cheperuiz | 10:163208bd16a8 | 27 | { |
| cheperuiz | 10:163208bd16a8 | 28 | case '0': //IDLE |
| cheperuiz | 10:163208bd16a8 | 29 | redLED = ON; |
| cheperuiz | 10:163208bd16a8 | 30 | greenLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 31 | blueLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 32 | break; |
| cheperuiz | 10:163208bd16a8 | 33 | |
| cheperuiz | 10:163208bd16a8 | 34 | case '1': //PLAY |
| cheperuiz | 10:163208bd16a8 | 35 | redLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 36 | greenLED = ON; |
| cheperuiz | 10:163208bd16a8 | 37 | blueLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 38 | break; |
| cheperuiz | 10:163208bd16a8 | 39 | |
| cheperuiz | 10:163208bd16a8 | 40 | case '2': //STOP |
| cheperuiz | 10:163208bd16a8 | 41 | redLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 42 | greenLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 43 | blueLED = ON; |
| cheperuiz | 10:163208bd16a8 | 44 | break; |
| cheperuiz | 10:163208bd16a8 | 45 | |
| cheperuiz | 10:163208bd16a8 | 46 | case '3': //REC |
| cheperuiz | 10:163208bd16a8 | 47 | redLED = ON; |
| cheperuiz | 10:163208bd16a8 | 48 | greenLED = ON; |
| cheperuiz | 10:163208bd16a8 | 49 | blueLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 50 | break; |
| cheperuiz | 10:163208bd16a8 | 51 | |
| cheperuiz | 10:163208bd16a8 | 52 | case '?': |
| cheperuiz | 10:163208bd16a8 | 53 | pc.putc(ID); |
| cheperuiz | 10:163208bd16a8 | 54 | break; |
| cheperuiz | 10:163208bd16a8 | 55 | |
| cheperuiz | 10:163208bd16a8 | 56 | default: |
| cheperuiz | 10:163208bd16a8 | 57 | redLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 58 | greenLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 59 | blueLED = OFF; |
| cheperuiz | 10:163208bd16a8 | 60 | break; |
| cheperuiz | 10:163208bd16a8 | 61 | } |
| cheperuiz | 10:163208bd16a8 | 62 | } |
| cheperuiz | 10:163208bd16a8 | 63 | wait(0.02); |
| chris | 0:0024ab6b9624 | 64 | } |
| chris | 0:0024ab6b9624 | 65 | } |
