Morse Code entry (Lab1 Part3)
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:e1478ad47f58
- Parent:
- 0:e7ca1ba9745c
--- a/main.cpp Thu Jan 29 21:09:01 2015 +0000 +++ b/main.cpp Sun Feb 08 15:44:04 2015 +0000 @@ -1,33 +1,48 @@ +//Part 3 +//This function is used to simply identify whether a specific +//input from a button is a dot or dash based on the length of +//time the button is pressed + #include "mbed.h" +//Initialize Interrupt InterruptIn pound(p25); +//Initialize Digital Out DigitalOut myled(LED1); +//Initialize Timers Timer t1; Timer t2; +//Serial Interface for Debugging Serial pc(USBTX, USBRX); +//Function to be called when button is pressed void pPress () { - t2.stop(); - if(t2.read_ms() > 400) - pc.printf(" "); - t1.start(); - myled = 1; + t2.stop(); //stop space timer + if(t2.read_ms() > 400)//if the length is greater than 400ms + pc.printf(" "); //space if added + t1.start(); //start dot/dash timer + myled = 1; //turn on led for debugging } + +//Function Called when button is released void pRelease() { - t1.stop(); - if(t1.read_ms() > 30 && t1.read_ms() <= 200) - pc.printf("."); + t1.stop(); //stop dot/dash timer + if(t1.read_ms() > 30 && t1.read_ms() <= 200) + pc.printf("."); //dot if length less than 200ms else if (t1.read_ms() > 200) - pc.printf("-"); + pc.printf("-"); //dash if length greater than 200ms myled = 0; - + //reset both timers t1.reset(); t2.reset(); + //start space timer t2.start(); } +//mainfunction int main() { myled = 0; + //Initialize Interrupts for rising/falling edge pound.rise(&pPress); pound.fall(&pRelease); t2.start();