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.
Fork of TextLCD_HelloWorld by
MorseCode.cpp
00001 //Morse Code Source File 00002 00003 #include "mbed.h" 00004 #include "TextLCD.h" 00005 00006 TextLCD lcd(p15, p16, p17, p18, p19, p20); // LED screen to display text as it is typed 00007 00008 int Value = 0; 00009 int First = 1; 00010 int ThreeZeros = 0; 00011 int SevenZeros = 0; 00012 int TenZeros = 0; 00013 00014 void printChar(int val) { 00015 switch(val) { 00016 case 0: // Printing 0 does nothing 00017 break; 00018 case 184: 00019 lcd.putc('a'); 00020 break; 00021 case 3752: 00022 lcd.putc('b'); 00023 break; 00024 case 15080: 00025 lcd.putc('c'); 00026 break; 00027 case 936: 00028 lcd.putc('d'); 00029 break; 00030 case 8: 00031 lcd.putc('e'); 00032 break; 00033 case 2792: 00034 lcd.putc('f'); 00035 break; 00036 case 3816: 00037 lcd.putc('g'); 00038 break; 00039 case 680: 00040 lcd.putc('h'); 00041 break; 00042 case 40: 00043 lcd.putc('i'); 00044 break; 00045 case 48056: 00046 lcd.putc('j'); 00047 break; 00048 case 3768: 00049 lcd.putc('k'); 00050 break; 00051 case 2984: 00052 lcd.putc('l'); 00053 break; 00054 case 952: 00055 lcd.putc('m'); 00056 break; 00057 case 232: 00058 lcd.putc('n'); 00059 break; 00060 case 15288: 00061 lcd.putc('o'); 00062 break; 00063 case 12008: 00064 lcd.putc('p'); 00065 break; 00066 case 61112: 00067 lcd.putc('q'); 00068 break; 00069 case 744: 00070 lcd.putc('r'); 00071 break; 00072 case 168: 00073 lcd.putc('s'); 00074 break; 00075 case 56: 00076 lcd.putc('t'); 00077 break; 00078 case 696: 00079 lcd.putc('u'); 00080 break; 00081 case 2744: 00082 lcd.putc('v'); 00083 break; 00084 case 3000: 00085 lcd.putc('w'); 00086 break; 00087 case 15032: 00088 lcd.putc('x'); 00089 break; 00090 case 60344: 00091 lcd.putc('y'); 00092 break; 00093 case 15272: 00094 lcd.putc('z'); 00095 break; 00096 } 00097 } 00098 00099 void MorseCode(int tick) { 00100 if(tick) { 00101 ThreeZeros = 0; 00102 SevenZeros = 0; 00103 TenZeros = 0; 00104 00105 //Update Value with a 1 00106 Value = Value << 1; 00107 Value += 1; 00108 } 00109 else { 00110 ThreeZeros += 1; 00111 SevenZeros += 1; 00112 TenZeros += 1; 00113 00114 //Update Value with a Zero 00115 Value = Value << 1; 00116 } 00117 00118 if(First) { 00119 lcd.cls(); 00120 First = 0; 00121 } 00122 00123 // Print Char if three zeros in a row 00124 if(ThreeZeros == 3) { 00125 printChar(Value); 00126 ThreeZeros = 0; 00127 Value = 0; 00128 } 00129 if(SevenZeros == 7) { // Space 00130 lcd.putc(' '); 00131 SevenZeros = 0; 00132 } 00133 if(TenZeros == 10) { // Clear 00134 lcd.cls(); 00135 SevenZeros = 0; 00136 TenZeros = 0; 00137 } 00138 }
Generated on Wed Jul 13 2022 01:41:04 by
