Morse Code Machine

Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld by Simon Ford

Committer:
Jgreub
Date:
Fri Mar 01 00:34:34 2013 +0000
Revision:
3:3f863fcfd172
Morse Code Machine

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jgreub 3:3f863fcfd172 1 //Morse Code Source File
Jgreub 3:3f863fcfd172 2
Jgreub 3:3f863fcfd172 3 #include "mbed.h"
Jgreub 3:3f863fcfd172 4 #include "TextLCD.h"
Jgreub 3:3f863fcfd172 5
Jgreub 3:3f863fcfd172 6 TextLCD lcd(p15, p16, p17, p18, p19, p20); // LED screen to display text as it is typed
Jgreub 3:3f863fcfd172 7
Jgreub 3:3f863fcfd172 8 int Value = 0;
Jgreub 3:3f863fcfd172 9 int First = 1;
Jgreub 3:3f863fcfd172 10 int ThreeZeros = 0;
Jgreub 3:3f863fcfd172 11 int SevenZeros = 0;
Jgreub 3:3f863fcfd172 12 int TenZeros = 0;
Jgreub 3:3f863fcfd172 13
Jgreub 3:3f863fcfd172 14 void printChar(int val) {
Jgreub 3:3f863fcfd172 15 switch(val) {
Jgreub 3:3f863fcfd172 16 case 0: // Printing 0 does nothing
Jgreub 3:3f863fcfd172 17 break;
Jgreub 3:3f863fcfd172 18 case 184:
Jgreub 3:3f863fcfd172 19 lcd.putc('a');
Jgreub 3:3f863fcfd172 20 break;
Jgreub 3:3f863fcfd172 21 case 3752:
Jgreub 3:3f863fcfd172 22 lcd.putc('b');
Jgreub 3:3f863fcfd172 23 break;
Jgreub 3:3f863fcfd172 24 case 15080:
Jgreub 3:3f863fcfd172 25 lcd.putc('c');
Jgreub 3:3f863fcfd172 26 break;
Jgreub 3:3f863fcfd172 27 case 936:
Jgreub 3:3f863fcfd172 28 lcd.putc('d');
Jgreub 3:3f863fcfd172 29 break;
Jgreub 3:3f863fcfd172 30 case 8:
Jgreub 3:3f863fcfd172 31 lcd.putc('e');
Jgreub 3:3f863fcfd172 32 break;
Jgreub 3:3f863fcfd172 33 case 2792:
Jgreub 3:3f863fcfd172 34 lcd.putc('f');
Jgreub 3:3f863fcfd172 35 break;
Jgreub 3:3f863fcfd172 36 case 3816:
Jgreub 3:3f863fcfd172 37 lcd.putc('g');
Jgreub 3:3f863fcfd172 38 break;
Jgreub 3:3f863fcfd172 39 case 680:
Jgreub 3:3f863fcfd172 40 lcd.putc('h');
Jgreub 3:3f863fcfd172 41 break;
Jgreub 3:3f863fcfd172 42 case 40:
Jgreub 3:3f863fcfd172 43 lcd.putc('i');
Jgreub 3:3f863fcfd172 44 break;
Jgreub 3:3f863fcfd172 45 case 48056:
Jgreub 3:3f863fcfd172 46 lcd.putc('j');
Jgreub 3:3f863fcfd172 47 break;
Jgreub 3:3f863fcfd172 48 case 3768:
Jgreub 3:3f863fcfd172 49 lcd.putc('k');
Jgreub 3:3f863fcfd172 50 break;
Jgreub 3:3f863fcfd172 51 case 2984:
Jgreub 3:3f863fcfd172 52 lcd.putc('l');
Jgreub 3:3f863fcfd172 53 break;
Jgreub 3:3f863fcfd172 54 case 952:
Jgreub 3:3f863fcfd172 55 lcd.putc('m');
Jgreub 3:3f863fcfd172 56 break;
Jgreub 3:3f863fcfd172 57 case 232:
Jgreub 3:3f863fcfd172 58 lcd.putc('n');
Jgreub 3:3f863fcfd172 59 break;
Jgreub 3:3f863fcfd172 60 case 15288:
Jgreub 3:3f863fcfd172 61 lcd.putc('o');
Jgreub 3:3f863fcfd172 62 break;
Jgreub 3:3f863fcfd172 63 case 12008:
Jgreub 3:3f863fcfd172 64 lcd.putc('p');
Jgreub 3:3f863fcfd172 65 break;
Jgreub 3:3f863fcfd172 66 case 61112:
Jgreub 3:3f863fcfd172 67 lcd.putc('q');
Jgreub 3:3f863fcfd172 68 break;
Jgreub 3:3f863fcfd172 69 case 744:
Jgreub 3:3f863fcfd172 70 lcd.putc('r');
Jgreub 3:3f863fcfd172 71 break;
Jgreub 3:3f863fcfd172 72 case 168:
Jgreub 3:3f863fcfd172 73 lcd.putc('s');
Jgreub 3:3f863fcfd172 74 break;
Jgreub 3:3f863fcfd172 75 case 56:
Jgreub 3:3f863fcfd172 76 lcd.putc('t');
Jgreub 3:3f863fcfd172 77 break;
Jgreub 3:3f863fcfd172 78 case 696:
Jgreub 3:3f863fcfd172 79 lcd.putc('u');
Jgreub 3:3f863fcfd172 80 break;
Jgreub 3:3f863fcfd172 81 case 2744:
Jgreub 3:3f863fcfd172 82 lcd.putc('v');
Jgreub 3:3f863fcfd172 83 break;
Jgreub 3:3f863fcfd172 84 case 3000:
Jgreub 3:3f863fcfd172 85 lcd.putc('w');
Jgreub 3:3f863fcfd172 86 break;
Jgreub 3:3f863fcfd172 87 case 15032:
Jgreub 3:3f863fcfd172 88 lcd.putc('x');
Jgreub 3:3f863fcfd172 89 break;
Jgreub 3:3f863fcfd172 90 case 60344:
Jgreub 3:3f863fcfd172 91 lcd.putc('y');
Jgreub 3:3f863fcfd172 92 break;
Jgreub 3:3f863fcfd172 93 case 15272:
Jgreub 3:3f863fcfd172 94 lcd.putc('z');
Jgreub 3:3f863fcfd172 95 break;
Jgreub 3:3f863fcfd172 96 }
Jgreub 3:3f863fcfd172 97 }
Jgreub 3:3f863fcfd172 98
Jgreub 3:3f863fcfd172 99 void MorseCode(int tick) {
Jgreub 3:3f863fcfd172 100 if(tick) {
Jgreub 3:3f863fcfd172 101 ThreeZeros = 0;
Jgreub 3:3f863fcfd172 102 SevenZeros = 0;
Jgreub 3:3f863fcfd172 103 TenZeros = 0;
Jgreub 3:3f863fcfd172 104
Jgreub 3:3f863fcfd172 105 //Update Value with a 1
Jgreub 3:3f863fcfd172 106 Value = Value << 1;
Jgreub 3:3f863fcfd172 107 Value += 1;
Jgreub 3:3f863fcfd172 108 }
Jgreub 3:3f863fcfd172 109 else {
Jgreub 3:3f863fcfd172 110 ThreeZeros += 1;
Jgreub 3:3f863fcfd172 111 SevenZeros += 1;
Jgreub 3:3f863fcfd172 112 TenZeros += 1;
Jgreub 3:3f863fcfd172 113
Jgreub 3:3f863fcfd172 114 //Update Value with a Zero
Jgreub 3:3f863fcfd172 115 Value = Value << 1;
Jgreub 3:3f863fcfd172 116 }
Jgreub 3:3f863fcfd172 117
Jgreub 3:3f863fcfd172 118 if(First) {
Jgreub 3:3f863fcfd172 119 lcd.cls();
Jgreub 3:3f863fcfd172 120 First = 0;
Jgreub 3:3f863fcfd172 121 }
Jgreub 3:3f863fcfd172 122
Jgreub 3:3f863fcfd172 123 // Print Char if three zeros in a row
Jgreub 3:3f863fcfd172 124 if(ThreeZeros == 3) {
Jgreub 3:3f863fcfd172 125 printChar(Value);
Jgreub 3:3f863fcfd172 126 ThreeZeros = 0;
Jgreub 3:3f863fcfd172 127 Value = 0;
Jgreub 3:3f863fcfd172 128 }
Jgreub 3:3f863fcfd172 129 if(SevenZeros == 7) { // Space
Jgreub 3:3f863fcfd172 130 lcd.putc(' ');
Jgreub 3:3f863fcfd172 131 SevenZeros = 0;
Jgreub 3:3f863fcfd172 132 }
Jgreub 3:3f863fcfd172 133 if(TenZeros == 10) { // Clear
Jgreub 3:3f863fcfd172 134 lcd.cls();
Jgreub 3:3f863fcfd172 135 SevenZeros = 0;
Jgreub 3:3f863fcfd172 136 TenZeros = 0;
Jgreub 3:3f863fcfd172 137 }
Jgreub 3:3f863fcfd172 138 }