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 4DGL-uLCD-SE
Fork of morseCode_1 by
Header_file.h@8:78b057dd6da4, 2018-05-01 (annotated)
- Committer:
- colson
- Date:
- Tue May 01 16:42:40 2018 +0000
- Revision:
- 8:78b057dd6da4
- Parent:
- 7:5a902d88277a
- Child:
- 9:3c1acc87b80c
Updated the tree, included traversal functionality
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeco13 | 2:d60577c26a58 | 1 | #include "mbed.h" |
colson | 4:62c590826ddb | 2 | #include "uLCD_4DGL.h" |
colson | 4:62c590826ddb | 3 | |
Jeco13 | 2:d60577c26a58 | 4 | |
Jeco13 | 2:d60577c26a58 | 5 | |
Jeco13 | 2:d60577c26a58 | 6 | AnalogOut speaker(p18); |
Jeco13 | 2:d60577c26a58 | 7 | DigitalOut led(p8); |
colson | 4:62c590826ddb | 8 | DigitalOut myled(LED1); |
colson | 4:62c590826ddb | 9 | DigitalOut testled(LED2); |
colson | 4:62c590826ddb | 10 | DigitalOut otherled(LED3); |
colson | 4:62c590826ddb | 11 | uLCD_4DGL uLCD(p28, p27, p29); // create a global uLCD object |
colson | 4:62c590826ddb | 12 | |
Jeco13 | 2:d60577c26a58 | 13 | |
Jeco13 | 2:d60577c26a58 | 14 | void dot(){ |
Jeco13 | 2:d60577c26a58 | 15 | //turn on speaker for 0.5s. |
Jeco13 | 2:d60577c26a58 | 16 | //turn on led for 0.5s. |
Jeco13 | 2:d60577c26a58 | 17 | //turn off speaker & led. |
colson | 4:62c590826ddb | 18 | testled = 1; |
colson | 4:62c590826ddb | 19 | wait(0.5); |
colson | 4:62c590826ddb | 20 | testled = 0; |
Jeco13 | 3:6e52b66c5a0c | 21 | wait(0.5); |
Jeco13 | 2:d60577c26a58 | 22 | } |
Jeco13 | 2:d60577c26a58 | 23 | |
Jeco13 | 2:d60577c26a58 | 24 | void dash(){ |
Jeco13 | 3:6e52b66c5a0c | 25 | //turn on speaker for 1s. |
Jeco13 | 3:6e52b66c5a0c | 26 | //turn on led for 1s. |
Jeco13 | 2:d60577c26a58 | 27 | //turn off speaker & led. |
colson | 4:62c590826ddb | 28 | myled = 1; |
colson | 4:62c590826ddb | 29 | wait(1.0); |
colson | 4:62c590826ddb | 30 | myled = 0; |
Jeco13 | 3:6e52b66c5a0c | 31 | wait(0.5); |
Jeco13 | 3:6e52b66c5a0c | 32 | } |
Jeco13 | 3:6e52b66c5a0c | 33 | |
colson | 6:421ece74143e | 34 | //I commented out the debug outputs since I solved the problem of what was wrong but it could be nice to keep around, I guess |
Jeco13 | 3:6e52b66c5a0c | 35 | void Text_to_morse(char input_char){ //function takes in characters at a time. call dot & dash appropriately for detected char |
Jeco13 | 3:6e52b66c5a0c | 36 | //int w = 0.5; //wait duration in-between led blinks and speaker clicks |
colson | 6:421ece74143e | 37 | //uLCD.printf("input: %c\n",input_char); //Debug output, feel free to comment out |
colson | 4:62c590826ddb | 38 | if(input_char == 'a' || input_char == 'A'){ |
colson | 6:421ece74143e | 39 | //uLCD.printf("a\n"); |
Jeco13 | 3:6e52b66c5a0c | 40 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 41 | //wait(w); //wait 0.5s in between |
Jeco13 | 3:6e52b66c5a0c | 42 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 43 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 44 | } |
colson | 4:62c590826ddb | 45 | else if(input_char == 'b' || input_char == 'B'){ |
colson | 6:421ece74143e | 46 | //uLCD.printf("b\n"); |
Jeco13 | 3:6e52b66c5a0c | 47 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 48 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 49 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 50 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 51 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 52 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 53 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 54 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 55 | } |
colson | 4:62c590826ddb | 56 | else if(input_char == 'c'||input_char == 'C'){ |
colson | 6:421ece74143e | 57 | //uLCD.printf("c\n"); |
Jeco13 | 3:6e52b66c5a0c | 58 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 59 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 60 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 61 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 62 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 63 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 64 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 65 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 66 | } |
colson | 4:62c590826ddb | 67 | else if(input_char == 'd'||input_char == 'D'){ |
colson | 6:421ece74143e | 68 | //uLCD.printf("d\n"); |
Jeco13 | 3:6e52b66c5a0c | 69 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 70 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 71 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 72 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 73 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 74 | //wait(w); |
colson | 4:62c590826ddb | 75 | }else if(input_char == 'e'||input_char == 'E'){ |
colson | 6:421ece74143e | 76 | //uLCD.printf("e\n"); |
Jeco13 | 3:6e52b66c5a0c | 77 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 78 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 79 | } |
colson | 4:62c590826ddb | 80 | else if(input_char == 'f'||input_char == 'F'){ |
colson | 6:421ece74143e | 81 | //uLCD.printf("f\n"); |
Jeco13 | 3:6e52b66c5a0c | 82 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 83 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 84 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 85 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 86 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 87 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 88 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 89 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 90 | } |
colson | 4:62c590826ddb | 91 | else if(input_char == 'g'||input_char == 'G'){ |
colson | 6:421ece74143e | 92 | //uLCD.printf("g\n"); |
Jeco13 | 3:6e52b66c5a0c | 93 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 94 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 95 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 96 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 97 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 98 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 99 | } |
colson | 4:62c590826ddb | 100 | else if(input_char == 'h'||input_char == 'H'){ |
colson | 6:421ece74143e | 101 | //uLCD.printf("h\n"); |
Jeco13 | 3:6e52b66c5a0c | 102 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 103 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 104 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 105 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 106 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 107 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 108 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 109 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 110 | } |
colson | 4:62c590826ddb | 111 | else if(input_char == 'i'||input_char == 'I'){ |
colson | 6:421ece74143e | 112 | //uLCD.printf("i\n"); |
Jeco13 | 3:6e52b66c5a0c | 113 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 114 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 115 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 116 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 117 | } |
colson | 4:62c590826ddb | 118 | else if(input_char == 'j'||input_char == 'J'){ |
colson | 6:421ece74143e | 119 | //uLCD.printf("j\n"); |
Jeco13 | 3:6e52b66c5a0c | 120 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 121 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 122 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 123 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 124 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 125 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 126 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 127 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 128 | } |
colson | 4:62c590826ddb | 129 | else if(input_char == 'k'||input_char == 'K'){ |
colson | 6:421ece74143e | 130 | //uLCD.printf("k\n"); |
Jeco13 | 3:6e52b66c5a0c | 131 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 132 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 133 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 134 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 135 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 136 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 137 | } |
colson | 4:62c590826ddb | 138 | else if(input_char == 'l'||input_char == 'L'){ |
colson | 6:421ece74143e | 139 | //uLCD.printf("l\n"); |
Jeco13 | 3:6e52b66c5a0c | 140 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 141 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 142 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 143 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 144 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 145 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 146 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 147 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 148 | } |
colson | 4:62c590826ddb | 149 | else if(input_char == 'm'||input_char == 'M'){ |
colson | 6:421ece74143e | 150 | //uLCD.printf("m\n"); |
Jeco13 | 3:6e52b66c5a0c | 151 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 152 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 153 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 154 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 155 | } |
colson | 4:62c590826ddb | 156 | else if(input_char == 'n'||input_char == 'N'){ |
colson | 6:421ece74143e | 157 | //uLCD.printf("n\n"); |
Jeco13 | 3:6e52b66c5a0c | 158 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 159 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 160 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 161 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 162 | } |
colson | 4:62c590826ddb | 163 | else if(input_char == 'o'|| input_char == 'O'){ |
colson | 6:421ece74143e | 164 | //uLCD.printf("o\n"); |
colson | 4:62c590826ddb | 165 | //testled = 1; |
colson | 4:62c590826ddb | 166 | dash(); |
colson | 4:62c590826ddb | 167 | //wait(2); |
Jeco13 | 3:6e52b66c5a0c | 168 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 169 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 170 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 171 | //wait(w); |
colson | 4:62c590826ddb | 172 | //testled = 0; |
Jeco13 | 3:6e52b66c5a0c | 173 | } |
colson | 4:62c590826ddb | 174 | else if(input_char == 'p'||input_char == 'P'){ |
colson | 6:421ece74143e | 175 | //uLCD.printf("p\n"); |
Jeco13 | 3:6e52b66c5a0c | 176 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 177 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 178 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 179 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 180 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 181 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 182 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 183 | //wait(w); |
Jeco13 | 3:6e52b66c5a0c | 184 | } |
colson | 4:62c590826ddb | 185 | else if(input_char == 'q'||input_char == 'Q'){ |
colson | 6:421ece74143e | 186 | //uLCD.printf("q\n"); |
Jeco13 | 3:6e52b66c5a0c | 187 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 188 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 189 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 190 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 191 | } |
colson | 4:62c590826ddb | 192 | else if(input_char == 'r'||input_char == 'R'){ |
colson | 6:421ece74143e | 193 | //uLCD.printf("r\n"); |
Jeco13 | 3:6e52b66c5a0c | 194 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 195 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 196 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 197 | } |
colson | 4:62c590826ddb | 198 | else if(input_char == 's'||input_char == 'S'){ |
colson | 6:421ece74143e | 199 | //uLCD.printf("s\n"); |
colson | 4:62c590826ddb | 200 | //otherled = 1; |
Jeco13 | 3:6e52b66c5a0c | 201 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 202 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 203 | dot(); |
colson | 4:62c590826ddb | 204 | //otherled = 0; |
Jeco13 | 3:6e52b66c5a0c | 205 | } |
colson | 4:62c590826ddb | 206 | else if(input_char == 't'||input_char == 'T'){ |
colson | 6:421ece74143e | 207 | //uLCD.printf("t\n"); |
Jeco13 | 3:6e52b66c5a0c | 208 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 209 | } |
colson | 4:62c590826ddb | 210 | else if(input_char == 'u'||input_char == 'U'){ |
colson | 6:421ece74143e | 211 | //uLCD.printf("u\n"); |
Jeco13 | 3:6e52b66c5a0c | 212 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 213 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 214 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 215 | } |
colson | 4:62c590826ddb | 216 | else if(input_char == 'v'||input_char == 'V'){ |
colson | 6:421ece74143e | 217 | //uLCD.printf("v\n"); |
Jeco13 | 3:6e52b66c5a0c | 218 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 219 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 220 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 221 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 222 | } |
colson | 4:62c590826ddb | 223 | else if(input_char == 'w'||input_char == 'W'){ |
colson | 6:421ece74143e | 224 | //uLCD.printf("w\n"); |
Jeco13 | 3:6e52b66c5a0c | 225 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 226 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 227 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 228 | } |
colson | 4:62c590826ddb | 229 | else if(input_char == 'x'||input_char == 'X'){ |
colson | 6:421ece74143e | 230 | //uLCD.printf("x\n"); |
Jeco13 | 3:6e52b66c5a0c | 231 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 232 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 233 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 234 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 235 | } |
colson | 4:62c590826ddb | 236 | else if(input_char == 'y'||input_char == 'Y'){ |
colson | 6:421ece74143e | 237 | //uLCD.printf("y\n"); |
Jeco13 | 3:6e52b66c5a0c | 238 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 239 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 240 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 241 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 242 | } |
colson | 4:62c590826ddb | 243 | else if(input_char == 'z'||input_char == 'Z'){ |
colson | 6:421ece74143e | 244 | //uLCD.printf("z\n"); |
Jeco13 | 3:6e52b66c5a0c | 245 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 246 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 247 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 248 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 249 | } |
Jeco13 | 3:6e52b66c5a0c | 250 | else if(input_char == '0'){ |
Jeco13 | 3:6e52b66c5a0c | 251 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 252 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 253 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 254 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 255 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 256 | } |
Jeco13 | 3:6e52b66c5a0c | 257 | else if(input_char == '1'){ |
Jeco13 | 3:6e52b66c5a0c | 258 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 259 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 260 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 261 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 262 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 263 | } |
Jeco13 | 3:6e52b66c5a0c | 264 | else if(input_char == '2'){ |
Jeco13 | 3:6e52b66c5a0c | 265 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 266 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 267 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 268 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 269 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 270 | } |
Jeco13 | 3:6e52b66c5a0c | 271 | else if(input_char == '3'){ |
Jeco13 | 3:6e52b66c5a0c | 272 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 273 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 274 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 275 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 276 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 277 | } |
Jeco13 | 3:6e52b66c5a0c | 278 | else if(input_char == '4'){ |
Jeco13 | 3:6e52b66c5a0c | 279 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 280 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 281 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 282 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 283 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 284 | } |
Jeco13 | 3:6e52b66c5a0c | 285 | else if(input_char == '5'){ |
Jeco13 | 3:6e52b66c5a0c | 286 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 287 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 288 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 289 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 290 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 291 | } |
Jeco13 | 3:6e52b66c5a0c | 292 | else if(input_char == '6'){ |
Jeco13 | 3:6e52b66c5a0c | 293 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 294 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 295 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 296 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 297 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 298 | } |
Jeco13 | 3:6e52b66c5a0c | 299 | else if(input_char == '7'){ |
Jeco13 | 3:6e52b66c5a0c | 300 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 301 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 302 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 303 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 304 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 305 | } |
Jeco13 | 3:6e52b66c5a0c | 306 | else if(input_char == '8'){ |
Jeco13 | 3:6e52b66c5a0c | 307 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 308 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 309 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 310 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 311 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 312 | } |
Jeco13 | 3:6e52b66c5a0c | 313 | else if(input_char == '9'){ |
Jeco13 | 3:6e52b66c5a0c | 314 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 315 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 316 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 317 | dash(); |
Jeco13 | 3:6e52b66c5a0c | 318 | dot(); |
Jeco13 | 3:6e52b66c5a0c | 319 | } |
Jeco13 | 3:6e52b66c5a0c | 320 | else{wait(1);}//error character, or space character. |
colson | 5:5b86521e418c | 321 | } |
colson | 5:5b86521e418c | 322 | |
colson | 8:78b057dd6da4 | 323 | struct node |
colson | 8:78b057dd6da4 | 324 | { |
colson | 8:78b057dd6da4 | 325 | char value; |
colson | 8:78b057dd6da4 | 326 | node * dot; |
colson | 8:78b057dd6da4 | 327 | node * dash; |
colson | 8:78b057dd6da4 | 328 | |
colson | 8:78b057dd6da4 | 329 | node(){ |
colson | 8:78b057dd6da4 | 330 | value = '*'; |
colson | 8:78b057dd6da4 | 331 | dot = NULL; |
colson | 8:78b057dd6da4 | 332 | dash = NULL; |
colson | 8:78b057dd6da4 | 333 | } |
colson | 8:78b057dd6da4 | 334 | }; |
colson | 8:78b057dd6da4 | 335 | |
colson | 5:5b86521e418c | 336 | class Tree { |
colson | 5:5b86521e418c | 337 | public: |
colson | 8:78b057dd6da4 | 338 | node *root; |
colson | 8:78b057dd6da4 | 339 | |
colson | 8:78b057dd6da4 | 340 | |
colson | 5:5b86521e418c | 341 | Tree(){} |
colson | 8:78b057dd6da4 | 342 | |
colson | 5:5b86521e418c | 343 | Tree createRoot(); |
colson | 8:78b057dd6da4 | 344 | //void insertdot(char newValue, Tree *rootNode); |
colson | 8:78b057dd6da4 | 345 | //void insertdash(char newValue, Tree *rootNode); |
colson | 8:78b057dd6da4 | 346 | //char returnvalue(Tree *rootNode); |
colson | 5:5b86521e418c | 347 | //void deleteNode(Tree *deleteNode); //Didn't see the need for a delete function since the tree is pretty static |
colson | 5:5b86521e418c | 348 | }; |
colson | 5:5b86521e418c | 349 | |
colson | 5:5b86521e418c | 350 | //Inserting an item on the "dot" side of a node |
colson | 5:5b86521e418c | 351 | //Adds the value, and pointers go to NULL |
colson | 6:421ece74143e | 352 | |
colson | 6:421ece74143e | 353 | //The current intent is that by pointing to a NULL type, we can know when to top traversing. |
colson | 6:421ece74143e | 354 | //I see our telegraph key having a separate function that will return a Tree node when traversing |
colson | 6:421ece74143e | 355 | //But if a NULL is pointed to next, then it'll return the node that it's already looking at |
colson | 6:421ece74143e | 356 | //If any of these comments make sense |
colson | 8:78b057dd6da4 | 357 | void insertdot(char newValue, node * rootNode){ |
colson | 8:78b057dd6da4 | 358 | node *temp = new node; |
colson | 8:78b057dd6da4 | 359 | rootNode->dot = temp; |
colson | 8:78b057dd6da4 | 360 | temp->value = newValue; |
colson | 8:78b057dd6da4 | 361 | temp->dot = NULL; |
colson | 8:78b057dd6da4 | 362 | temp->dash = NULL; |
colson | 5:5b86521e418c | 363 | return; |
colson | 5:5b86521e418c | 364 | } |
colson | 5:5b86521e418c | 365 | |
colson | 5:5b86521e418c | 366 | //Inserting an item on the "dash" side of a node |
colson | 6:421ece74143e | 367 | //See above for more comments/documentation |
colson | 8:78b057dd6da4 | 368 | |
colson | 8:78b057dd6da4 | 369 | void insertdash(char newValue, node * rootNode){ |
colson | 8:78b057dd6da4 | 370 | node *temp = new node; |
colson | 8:78b057dd6da4 | 371 | rootNode->dash = temp; |
colson | 8:78b057dd6da4 | 372 | temp->value = newValue; |
colson | 8:78b057dd6da4 | 373 | temp->dot = NULL; |
colson | 8:78b057dd6da4 | 374 | temp->dash = NULL; |
colson | 5:5b86521e418c | 375 | return; |
colson | 5:5b86521e418c | 376 | } |
colson | 5:5b86521e418c | 377 | |
colson | 6:421ece74143e | 378 | //Return char type value stored in a given node |
colson | 8:78b057dd6da4 | 379 | char returnvalue(node *rootNode){ |
colson | 5:5b86521e418c | 380 | return rootNode->value; |
colson | 5:5b86521e418c | 381 | } |
colson | 5:5b86521e418c | 382 | |
colson | 8:78b057dd6da4 | 383 | node traverseDot(node * rootNode){ |
colson | 8:78b057dd6da4 | 384 | node * tempNode = new node; |
colson | 8:78b057dd6da4 | 385 | if(rootNode->dot == NULL){ |
colson | 8:78b057dd6da4 | 386 | printf("null\n"); |
colson | 8:78b057dd6da4 | 387 | return * rootNode; |
colson | 8:78b057dd6da4 | 388 | } |
colson | 8:78b057dd6da4 | 389 | else{ |
colson | 8:78b057dd6da4 | 390 | cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dot) << " return dot" << endl; |
colson | 8:78b057dd6da4 | 391 | rootNode = rootNode->dot; |
colson | 8:78b057dd6da4 | 392 | return *rootNode; |
colson | 8:78b057dd6da4 | 393 | } |
colson | 8:78b057dd6da4 | 394 | } |
colson | 8:78b057dd6da4 | 395 | |
colson | 8:78b057dd6da4 | 396 | node traverseDash(node * rootNode){ |
colson | 8:78b057dd6da4 | 397 | if(rootNode->dash == NULL){ |
colson | 8:78b057dd6da4 | 398 | printf("null\n"); |
colson | 8:78b057dd6da4 | 399 | return * rootNode; |
colson | 8:78b057dd6da4 | 400 | } |
colson | 8:78b057dd6da4 | 401 | else{ |
colson | 8:78b057dd6da4 | 402 | cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dash) << " return dash" << endl; |
colson | 8:78b057dd6da4 | 403 | rootNode = rootNode->dash; |
colson | 8:78b057dd6da4 | 404 | return * rootNode; |
colson | 8:78b057dd6da4 | 405 | } |
colson | 8:78b057dd6da4 | 406 | } |
colson | 8:78b057dd6da4 | 407 | |
colson | 5:5b86521e418c | 408 | |
colson | 5:5b86521e418c | 409 |