Interactive Alarm Clock Code
Dependencies: 4DGL-uLCD-SE mbed
ledColorSequence.cpp@0:68a3851de2ee, 2015-12-10 (annotated)
- Committer:
- tshin7
- Date:
- Thu Dec 10 08:59:55 2015 +0000
- Revision:
- 0:68a3851de2ee
Alarm Clock
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tshin7 | 0:68a3851de2ee | 1 | #include "mbed.h" |
tshin7 | 0:68a3851de2ee | 2 | #include "timeDisplay.h" |
tshin7 | 0:68a3851de2ee | 3 | #include "setAlarm.h" |
tshin7 | 0:68a3851de2ee | 4 | #include "ledColorSequence.h" |
tshin7 | 0:68a3851de2ee | 5 | #include <string> |
tshin7 | 0:68a3851de2ee | 6 | |
tshin7 | 0:68a3851de2ee | 7 | Serial pc(USBTX,USBRX); |
tshin7 | 0:68a3851de2ee | 8 | DigitalOut red(p22); |
tshin7 | 0:68a3851de2ee | 9 | DigitalOut green(p23); |
tshin7 | 0:68a3851de2ee | 10 | DigitalOut blue(p24); |
tshin7 | 0:68a3851de2ee | 11 | int color; |
tshin7 | 0:68a3851de2ee | 12 | int colorCount=0; |
tshin7 | 0:68a3851de2ee | 13 | char colorSequence[5]; |
tshin7 | 0:68a3851de2ee | 14 | |
tshin7 | 0:68a3851de2ee | 15 | string ledColorSequence::chooseColor() |
tshin7 | 0:68a3851de2ee | 16 | { |
tshin7 | 0:68a3851de2ee | 17 | while(colorCount<4){ |
tshin7 | 0:68a3851de2ee | 18 | color = rand()%3; |
tshin7 | 0:68a3851de2ee | 19 | if (color==0){ |
tshin7 | 0:68a3851de2ee | 20 | red=1; |
tshin7 | 0:68a3851de2ee | 21 | colorSequence[colorCount] = 'r'; |
tshin7 | 0:68a3851de2ee | 22 | wait(0.4); |
tshin7 | 0:68a3851de2ee | 23 | red=0; |
tshin7 | 0:68a3851de2ee | 24 | }else if (color==1){ |
tshin7 | 0:68a3851de2ee | 25 | green=1; |
tshin7 | 0:68a3851de2ee | 26 | colorSequence[colorCount] = 'g'; |
tshin7 | 0:68a3851de2ee | 27 | wait(0.4); |
tshin7 | 0:68a3851de2ee | 28 | green=0; |
tshin7 | 0:68a3851de2ee | 29 | }else if (color==2) { |
tshin7 | 0:68a3851de2ee | 30 | blue=1; |
tshin7 | 0:68a3851de2ee | 31 | colorSequence[colorCount] = 'b'; |
tshin7 | 0:68a3851de2ee | 32 | wait(0.4); |
tshin7 | 0:68a3851de2ee | 33 | blue=0; |
tshin7 | 0:68a3851de2ee | 34 | } |
tshin7 | 0:68a3851de2ee | 35 | colorCount++; |
tshin7 | 0:68a3851de2ee | 36 | } |
tshin7 | 0:68a3851de2ee | 37 | colorSequence[4]='\0'; |
tshin7 | 0:68a3851de2ee | 38 | colorCount=0; |
tshin7 | 0:68a3851de2ee | 39 | return colorSequence; |
tshin7 | 0:68a3851de2ee | 40 | } |
tshin7 | 0:68a3851de2ee | 41 | |
tshin7 | 0:68a3851de2ee | 42 | void ledColorSequence::repeatColorSequence(string colorSequence) |
tshin7 | 0:68a3851de2ee | 43 | { |
tshin7 | 0:68a3851de2ee | 44 | while(colorCount<4){ |
tshin7 | 0:68a3851de2ee | 45 | if (colorSequence[colorCount] == 'r'){ |
tshin7 | 0:68a3851de2ee | 46 | red=1; |
tshin7 | 0:68a3851de2ee | 47 | wait(0.4); |
tshin7 | 0:68a3851de2ee | 48 | red=0; |
tshin7 | 0:68a3851de2ee | 49 | }else if (colorSequence[colorCount] == 'g'){ |
tshin7 | 0:68a3851de2ee | 50 | green=1; |
tshin7 | 0:68a3851de2ee | 51 | wait(0.4); |
tshin7 | 0:68a3851de2ee | 52 | green=0; |
tshin7 | 0:68a3851de2ee | 53 | }else if (colorSequence[colorCount] == 'b') { |
tshin7 | 0:68a3851de2ee | 54 | blue=1; |
tshin7 | 0:68a3851de2ee | 55 | wait(0.4); |
tshin7 | 0:68a3851de2ee | 56 | blue=0; |
tshin7 | 0:68a3851de2ee | 57 | } |
tshin7 | 0:68a3851de2ee | 58 | colorCount++; |
tshin7 | 0:68a3851de2ee | 59 | } |
tshin7 | 0:68a3851de2ee | 60 | colorCount=0; |
tshin7 | 0:68a3851de2ee | 61 | } |
tshin7 | 0:68a3851de2ee | 62 | |
tshin7 | 0:68a3851de2ee | 63 | void ledColorSequence::turnOffColor() |
tshin7 | 0:68a3851de2ee | 64 | { |
tshin7 | 0:68a3851de2ee | 65 | if (blue==1||green==1||red==1){ |
tshin7 | 0:68a3851de2ee | 66 | blue=0; |
tshin7 | 0:68a3851de2ee | 67 | green=0; |
tshin7 | 0:68a3851de2ee | 68 | red=0; |
tshin7 | 0:68a3851de2ee | 69 | } |
tshin7 | 0:68a3851de2ee | 70 | } |
tshin7 | 0:68a3851de2ee | 71 |