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.
Dependencies: mbed
Revision 0:d8278eb58283, committed 2015-02-08
- Comitter:
- jaredwil
- Date:
- Sun Feb 08 15:08:28 2015 +0000
- Commit message:
- Extra Credit 1 done;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d8278eb58283 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Feb 08 15:08:28 2015 +0000 @@ -0,0 +1,124 @@ +#include "mbed.h" +#include <map> +#include <string> + +InterruptIn pound(p25); +DigitalOut myled(LED1); +DigitalOut dot(p20); +DigitalOut dash(p19); +DigitalOut buzz(p18); + +Timer t1; +Timer t2; + +std::map<std::string, char> asciiMap; + +Serial pc(USBTX, USBRX); +std::string curStr; + +int state = 0; + +void init(){ + asciiMap[".-"]='a'; + asciiMap["-..."]='b'; + asciiMap["-.-."]='c'; + asciiMap["-.."]='d'; + asciiMap["."]='e'; + asciiMap["..-."]='f'; + asciiMap["--."]='g'; + asciiMap["...."]='h'; + asciiMap[".."]='i'; + asciiMap[".---"]='j'; + asciiMap["-.-"]='k'; + asciiMap[".-.."]='l'; + asciiMap["--"]='m'; + asciiMap["-."]='n'; + asciiMap["---"]='o'; + asciiMap[".--."]='p'; + asciiMap["--.-"]='q'; + asciiMap[".-."]='r'; + asciiMap["..."]='s'; + asciiMap["-"]='t'; + asciiMap["..-"]='u'; + asciiMap["...-"]='v'; + asciiMap[".--"]='w'; + asciiMap["-..-"]='x'; + asciiMap["-.--"]='y'; + asciiMap["--.."]='z'; + asciiMap[".----"]='1'; + asciiMap["..---"]='2'; + asciiMap["...--"]='3'; + asciiMap["....-"]='4'; + asciiMap["....."]='5'; + asciiMap["-...."]='6'; + asciiMap["--..."]='7'; + asciiMap["---.."]='8'; + asciiMap["----."]='9'; + asciiMap["-----"]='0'; +} + +void pPress () { + t2.stop(); + + t1.start(); + myled = 1; + buzz = 0; + + } +void pRelease() { + t1.stop(); + if(t1.read_ms() > 30 && t1.read_ms() <= 200){ + dot = 0; + buzz =0; + curStr = curStr + "."; + //pc.printf("."); + } + else if (t1.read_ms() > 200) { + //dash= 0; + //buzz = 0; + curStr = curStr + "-"; + //pc.printf("-"); + } + wait(0.1); + t1.reset(); + t2.reset(); + state = 1; + + dot = 1; + buzz = 1; + //dash = 1; + myled = 0; + + t2.start(); + } +int main() { + init(); + dot=1; + dash=1; + buzz = 1; + myled = 0; + pound.rise(&pPress); + pound.fall(&pRelease); + t2.start(); + while(1) { + if(t1.read_ms()> 200) { + dash = 0; + buzz = 0; + wait(0.1); + dash = 1; + buzz =1; + } + char c; + if(t2.read_ms() > 400 && state ==1) { + dot = 1; + dash= 1; + buzz = 1; + c = asciiMap[curStr]; + pc.printf("%s : %c",curStr,c); + curStr.clear(); + pc.printf(" "); + state =0; + //pc.printf("%s",curStr); + } + } +} \ No newline at end of file
diff -r 000000000000 -r d8278eb58283 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Feb 08 15:08:28 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file