Joe Greubel
/
MorseCode
Morse Code Machine
Fork of TextLCD_HelloWorld by
Revision 3:3f863fcfd172, committed 2013-03-01
- Comitter:
- Jgreub
- Date:
- Fri Mar 01 00:34:34 2013 +0000
- Parent:
- 2:ad0b044d0a10
- Commit message:
- Morse Code Machine
Changed in this revision
diff -r ad0b044d0a10 -r 3f863fcfd172 MorseCode.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MorseCode.cpp Fri Mar 01 00:34:34 2013 +0000 @@ -0,0 +1,138 @@ +//Morse Code Source File + +#include "mbed.h" +#include "TextLCD.h" + +TextLCD lcd(p15, p16, p17, p18, p19, p20); // LED screen to display text as it is typed + +int Value = 0; +int First = 1; +int ThreeZeros = 0; +int SevenZeros = 0; +int TenZeros = 0; + +void printChar(int val) { + switch(val) { + case 0: // Printing 0 does nothing + break; + case 184: + lcd.putc('a'); + break; + case 3752: + lcd.putc('b'); + break; + case 15080: + lcd.putc('c'); + break; + case 936: + lcd.putc('d'); + break; + case 8: + lcd.putc('e'); + break; + case 2792: + lcd.putc('f'); + break; + case 3816: + lcd.putc('g'); + break; + case 680: + lcd.putc('h'); + break; + case 40: + lcd.putc('i'); + break; + case 48056: + lcd.putc('j'); + break; + case 3768: + lcd.putc('k'); + break; + case 2984: + lcd.putc('l'); + break; + case 952: + lcd.putc('m'); + break; + case 232: + lcd.putc('n'); + break; + case 15288: + lcd.putc('o'); + break; + case 12008: + lcd.putc('p'); + break; + case 61112: + lcd.putc('q'); + break; + case 744: + lcd.putc('r'); + break; + case 168: + lcd.putc('s'); + break; + case 56: + lcd.putc('t'); + break; + case 696: + lcd.putc('u'); + break; + case 2744: + lcd.putc('v'); + break; + case 3000: + lcd.putc('w'); + break; + case 15032: + lcd.putc('x'); + break; + case 60344: + lcd.putc('y'); + break; + case 15272: + lcd.putc('z'); + break; + } +} + +void MorseCode(int tick) { + if(tick) { + ThreeZeros = 0; + SevenZeros = 0; + TenZeros = 0; + + //Update Value with a 1 + Value = Value << 1; + Value += 1; + } + else { + ThreeZeros += 1; + SevenZeros += 1; + TenZeros += 1; + + //Update Value with a Zero + Value = Value << 1; + } + + if(First) { + lcd.cls(); + First = 0; + } + + // Print Char if three zeros in a row + if(ThreeZeros == 3) { + printChar(Value); + ThreeZeros = 0; + Value = 0; + } + if(SevenZeros == 7) { // Space + lcd.putc(' '); + SevenZeros = 0; + } + if(TenZeros == 10) { // Clear + lcd.cls(); + SevenZeros = 0; + TenZeros = 0; + } +} \ No newline at end of file
diff -r ad0b044d0a10 -r 3f863fcfd172 MorseCode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MorseCode.h Fri Mar 01 00:34:34 2013 +0000 @@ -0,0 +1,2 @@ +// Morse Code Header File February 27, 2013 +void MorseCode(int tick); \ No newline at end of file
diff -r ad0b044d0a10 -r 3f863fcfd172 main.cpp --- a/main.cpp Sat Dec 04 11:31:07 2010 +0000 +++ b/main.cpp Fri Mar 01 00:34:34 2013 +0000 @@ -1,10 +1,53 @@ -// Hello World! for the TextLCD +// Morse Code Machine February 27, 2013 #include "mbed.h" -#include "TextLCD.h" +#include "MorseCode.h" -TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 +//Need to Setup LCD Screen as TextLCD lcd(p15, p16, p17, p18, p19, p20) - Is included in MorseCode.cpp +DigitalIn Button(p8); // Button for User to Input Morse Code +DigitalOut LED(LED1); // LED to Indicate Time (every 1 seconds) +PwmOut Speaker(p21); // Speaker to play noise when button pushed +Timer Time; // Keeps track of time int main() { - lcd.printf("Hello World!\n"); + // Setup + int up = 0; + int read = 0; + Button.mode(PullUp); + Speaker.period(1.0/800.0); + Time.start(); + + //Start + while(1) { + + //Timer For User Comfort + if(Time.read_ms()%1000<15) { + up = !up; + read = 0; // Reset for Next Second + if((Time.read_ms() - 1740000) > 0) { + Time.reset(); // Reset if more than 29 minutes. + } + wait_ms(15); + } + + // LED Ticker + LED = (up)? 1 : 0; + + // Audio + if(!Button) { + Speaker = 0.25; // Volume + wait_ms(15); + } + else { + Speaker = 0.0; //Mute + wait_ms(15); + } + + // Do Morse Code + if(Time.read_ms()%1000 > 500 && read == 0) { // Half a Second Has Passed + read = 1; + MorseCode(!Button); // Read Button Value + } + + }// End While }