Connect a buzzer using D7 as vcc and D4 as gnd. Enter what you want to convert to morse using serial
Dependencies: mbed
Revision 1:f5b33cb527ce, committed 2015-10-23
- Comitter:
- sinx
- Date:
- Fri Oct 23 14:01:51 2015 +0000
- Parent:
- 0:3669c33270c9
- Commit message:
- with sound;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Oct 22 09:31:36 2015 +0000 +++ b/main.cpp Fri Oct 23 14:01:51 2015 +0000 @@ -1,7 +1,8 @@ #include "mbed.h" Serial pc(USBTX, USBRX); -DigitalOut led(LED1); +DigitalOut led(D7); +DigitalOut gnd(D4); //0=dot,1=dash, 2=space //1. The length of a dot is one unit.2. A dash is three units.3. The space between parts of the same letter is one unit.4. The space between letters is three units.5. The space between words is seven units. @@ -17,7 +18,7 @@ {1,0,0,0,0},/*6*/ {1,1,0,0,0},/*7*/ {1,1,1,0,0},/*8*/ {1,1,1,1,0},/*9*/ {2,3,3,3,3}/*space */ }; -float unitInSeconds=(float)0.1; +float unitInSeconds=(float)0.05; float dot=unitInSeconds; float dash=unitInSeconds*(float)3; float internalLetterSepeator=dot; @@ -32,7 +33,8 @@ int main() { - led=1; + gnd=0; + led=0; printf("Enter the sentence you want to morse\r\n"); int count = 0; while (count < (99)) { @@ -50,7 +52,7 @@ for (int i =0; i < sizeof(sentence); i++) { morse(sentence[i]); } - wait(2*space); + wait(10*space); } } @@ -101,6 +103,7 @@ { case 0:{ led=1; + printf("dot "); wait(dot); led=0; wait(dot); @@ -108,6 +111,7 @@ } case 1:{ led=1; + printf("dash "); wait(dash); led=0; wait(dot); @@ -115,10 +119,11 @@ } case 2:{ led=0; + printf("space "); wait(space); break; } - case 3:{ + default:{ break; } }