7 Segment dash dot
Dependencies: mbed
main.cpp@0:382ba90ab57f, 2015-02-02 (annotated)
- Committer:
- sandeshkumar
- Date:
- Mon Feb 02 21:46:26 2015 +0000
- Revision:
- 0:382ba90ab57f
Initial Commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandeshkumar | 0:382ba90ab57f | 1 | #include "mbed.h" |
sandeshkumar | 0:382ba90ab57f | 2 | |
sandeshkumar | 0:382ba90ab57f | 3 | InterruptIn pin22(p22); |
sandeshkumar | 0:382ba90ab57f | 4 | DigitalOut led1(LED1); |
sandeshkumar | 0:382ba90ab57f | 5 | |
sandeshkumar | 0:382ba90ab57f | 6 | DigitalOut dash(p19); |
sandeshkumar | 0:382ba90ab57f | 7 | DigitalOut dot(p20); |
sandeshkumar | 0:382ba90ab57f | 8 | |
sandeshkumar | 0:382ba90ab57f | 9 | Timer interruptTimer; |
sandeshkumar | 0:382ba90ab57f | 10 | Timer spaceCountTimer; |
sandeshkumar | 0:382ba90ab57f | 11 | |
sandeshkumar | 0:382ba90ab57f | 12 | bool isInterruptTimerRunning = 1; |
sandeshkumar | 0:382ba90ab57f | 13 | |
sandeshkumar | 0:382ba90ab57f | 14 | Serial pc(USBTX, USBRX);//tx, rx |
sandeshkumar | 0:382ba90ab57f | 15 | |
sandeshkumar | 0:382ba90ab57f | 16 | void classify(int elapsedTime) { |
sandeshkumar | 0:382ba90ab57f | 17 | if(elapsedTime >= 30 && elapsedTime < 200) { |
sandeshkumar | 0:382ba90ab57f | 18 | pc.printf("Dot\t"); |
sandeshkumar | 0:382ba90ab57f | 19 | dot = 0; |
sandeshkumar | 0:382ba90ab57f | 20 | wait(0.05); |
sandeshkumar | 0:382ba90ab57f | 21 | dot = 1; |
sandeshkumar | 0:382ba90ab57f | 22 | |
sandeshkumar | 0:382ba90ab57f | 23 | } else if(elapsedTime < 400 && elapsedTime >= 200) { |
sandeshkumar | 0:382ba90ab57f | 24 | pc.printf("Dash\t"); |
sandeshkumar | 0:382ba90ab57f | 25 | dash = 0; |
sandeshkumar | 0:382ba90ab57f | 26 | wait(0.05); |
sandeshkumar | 0:382ba90ab57f | 27 | dash = 1; |
sandeshkumar | 0:382ba90ab57f | 28 | } |
sandeshkumar | 0:382ba90ab57f | 29 | |
sandeshkumar | 0:382ba90ab57f | 30 | } |
sandeshkumar | 0:382ba90ab57f | 31 | |
sandeshkumar | 0:382ba90ab57f | 32 | void checkForSpace(int elapsedTime) { |
sandeshkumar | 0:382ba90ab57f | 33 | if(elapsedTime > 400) { |
sandeshkumar | 0:382ba90ab57f | 34 | pc.printf("Space\t"); |
sandeshkumar | 0:382ba90ab57f | 35 | spaceCountTimer.reset(); |
sandeshkumar | 0:382ba90ab57f | 36 | } |
sandeshkumar | 0:382ba90ab57f | 37 | |
sandeshkumar | 0:382ba90ab57f | 38 | } |
sandeshkumar | 0:382ba90ab57f | 39 | |
sandeshkumar | 0:382ba90ab57f | 40 | void riseLed1() { |
sandeshkumar | 0:382ba90ab57f | 41 | // int elapsedTime = spaceCountTimer.read_ms(); |
sandeshkumar | 0:382ba90ab57f | 42 | // checkForSpace(elapsedTime); |
sandeshkumar | 0:382ba90ab57f | 43 | spaceCountTimer.reset(); |
sandeshkumar | 0:382ba90ab57f | 44 | if(isInterruptTimerRunning) { |
sandeshkumar | 0:382ba90ab57f | 45 | interruptTimer.start(); |
sandeshkumar | 0:382ba90ab57f | 46 | } else { |
sandeshkumar | 0:382ba90ab57f | 47 | interruptTimer.reset(); |
sandeshkumar | 0:382ba90ab57f | 48 | } |
sandeshkumar | 0:382ba90ab57f | 49 | led1 = 1; |
sandeshkumar | 0:382ba90ab57f | 50 | } |
sandeshkumar | 0:382ba90ab57f | 51 | |
sandeshkumar | 0:382ba90ab57f | 52 | void fallLed1() { |
sandeshkumar | 0:382ba90ab57f | 53 | int elapsedTime = interruptTimer.read_ms(); |
sandeshkumar | 0:382ba90ab57f | 54 | // interruptTimer.stop(); |
sandeshkumar | 0:382ba90ab57f | 55 | classify(elapsedTime); |
sandeshkumar | 0:382ba90ab57f | 56 | isInterruptTimerRunning = 0; |
sandeshkumar | 0:382ba90ab57f | 57 | spaceCountTimer.reset(); |
sandeshkumar | 0:382ba90ab57f | 58 | led1 = 0; |
sandeshkumar | 0:382ba90ab57f | 59 | } |
sandeshkumar | 0:382ba90ab57f | 60 | |
sandeshkumar | 0:382ba90ab57f | 61 | int main() { |
sandeshkumar | 0:382ba90ab57f | 62 | |
sandeshkumar | 0:382ba90ab57f | 63 | spaceCountTimer.start(); |
sandeshkumar | 0:382ba90ab57f | 64 | pc.baud(9600); |
sandeshkumar | 0:382ba90ab57f | 65 | |
sandeshkumar | 0:382ba90ab57f | 66 | dot = 1; |
sandeshkumar | 0:382ba90ab57f | 67 | dash = 1; |
sandeshkumar | 0:382ba90ab57f | 68 | |
sandeshkumar | 0:382ba90ab57f | 69 | int elapsedTime; |
sandeshkumar | 0:382ba90ab57f | 70 | |
sandeshkumar | 0:382ba90ab57f | 71 | pin22.rise(&riseLed1); // attach the address of the flip function to the rising edge |
sandeshkumar | 0:382ba90ab57f | 72 | pin22.fall(&fallLed1); |
sandeshkumar | 0:382ba90ab57f | 73 | while(1) { // wait around, interrupts will interrupt this! |
sandeshkumar | 0:382ba90ab57f | 74 | // wait(0.1); |
sandeshkumar | 0:382ba90ab57f | 75 | elapsedTime = spaceCountTimer.read_ms(); |
sandeshkumar | 0:382ba90ab57f | 76 | checkForSpace(elapsedTime); |
sandeshkumar | 0:382ba90ab57f | 77 | } |
sandeshkumar | 0:382ba90ab57f | 78 | |
sandeshkumar | 0:382ba90ab57f | 79 | |
sandeshkumar | 0:382ba90ab57f | 80 | } |