![](/media/cache/profiles/8757150decbd89b0f5442ca3db4d0e0e.50x50_q85.jpg)
John's code modified for envelope shaping and different colours
Fork of Morse-buddy-JohnF by
Morse_Code.cpp@2:260128ae5746, 2013-06-27 (annotated)
- Committer:
- tony1tf
- Date:
- Thu Jun 27 10:52:29 2013 +0000
- Revision:
- 2:260128ae5746
- Parent:
- 1:ba9c803c7596
- Child:
- 3:cbd036b6942b
Audio envelope shaping and changing coloured LED added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony1tf | 0:8c725fbd8e0e | 1 | |
tony1tf | 0:8c725fbd8e0e | 2 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 3 | // Morse Code June 30, 2011 John H. Fisher - K5JHF |
tony1tf | 0:8c725fbd8e0e | 4 | //============================================================== |
tony1tf | 2:260128ae5746 | 5 | // mods by Tony Abbey for envelope shaping and coloured LEDs - 27 June 2013 |
tony1tf | 0:8c725fbd8e0e | 6 | |
tony1tf | 0:8c725fbd8e0e | 7 | #include "mbed.h" |
tony1tf | 0:8c725fbd8e0e | 8 | |
tony1tf | 0:8c725fbd8e0e | 9 | #include "main.h" |
tony1tf | 0:8c725fbd8e0e | 10 | |
tony1tf | 0:8c725fbd8e0e | 11 | #include "Morse_Code.h" |
tony1tf | 0:8c725fbd8e0e | 12 | |
tony1tf | 0:8c725fbd8e0e | 13 | const float sine_wave [ 32 ] = { |
tony1tf | 0:8c725fbd8e0e | 14 | |
tony1tf | 2:260128ae5746 | 15 | sin ( 1 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 16 | sin ( 2 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 17 | sin ( 3 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 18 | sin ( 4 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 19 | sin ( 5 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 20 | sin ( 6 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 21 | sin ( 7 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 22 | sin ( 8 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 23 | sin ( 9 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 24 | sin ( 10 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 25 | sin ( 11 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 26 | sin ( 12 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 27 | sin ( 13 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 28 | sin ( 14 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 29 | sin ( 15 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 30 | sin ( 16 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 31 | sin ( 17 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 32 | sin ( 18 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 33 | sin ( 19 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 34 | sin ( 20 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 35 | sin ( 21 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 36 | sin ( 22 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 37 | sin ( 23 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 38 | sin ( 24 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 39 | sin ( 25 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 40 | sin ( 26 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 41 | sin ( 27 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 42 | sin ( 28 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 43 | sin ( 29 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 44 | sin ( 30 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 45 | sin ( 31 * step ) / 2.5 , |
tony1tf | 2:260128ae5746 | 46 | sin ( 0 * step ) / 2.5 |
tony1tf | 0:8c725fbd8e0e | 47 | |
tony1tf | 0:8c725fbd8e0e | 48 | }; |
tony1tf | 0:8c725fbd8e0e | 49 | |
tony1tf | 0:8c725fbd8e0e | 50 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 51 | |
tony1tf | 0:8c725fbd8e0e | 52 | Morse_Code::Morse_Code ( float WPM_Character, |
tony1tf | 0:8c725fbd8e0e | 53 | float WPM_Speed, |
tony1tf | 2:260128ae5746 | 54 | int Tone_Frequency, |
tony1tf | 2:260128ae5746 | 55 | char colour ) { |
tony1tf | 0:8c725fbd8e0e | 56 | |
tony1tf | 0:8c725fbd8e0e | 57 | _WPM_Character = WPM_Character; |
tony1tf | 0:8c725fbd8e0e | 58 | |
tony1tf | 0:8c725fbd8e0e | 59 | _WPM_Speed = WPM_Speed; |
tony1tf | 0:8c725fbd8e0e | 60 | |
tony1tf | 0:8c725fbd8e0e | 61 | _Tone_Frequency = Tone_Frequency; |
tony1tf | 0:8c725fbd8e0e | 62 | |
tony1tf | 2:260128ae5746 | 63 | _colour = colour; |
tony1tf | 0:8c725fbd8e0e | 64 | |
tony1tf | 0:8c725fbd8e0e | 65 | Calculate_Morse_Timing ( _WPM_Speed, _WPM_Character ); |
tony1tf | 0:8c725fbd8e0e | 66 | |
tony1tf | 0:8c725fbd8e0e | 67 | Practice_On(); |
tony1tf | 0:8c725fbd8e0e | 68 | |
tony1tf | 0:8c725fbd8e0e | 69 | } |
tony1tf | 0:8c725fbd8e0e | 70 | |
tony1tf | 0:8c725fbd8e0e | 71 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 72 | |
tony1tf | 0:8c725fbd8e0e | 73 | void Morse_Code::Sound_On ( void ) { |
tony1tf | 0:8c725fbd8e0e | 74 | |
tony1tf | 0:8c725fbd8e0e | 75 | Morse_Flag._Sound = 1; |
tony1tf | 0:8c725fbd8e0e | 76 | |
tony1tf | 0:8c725fbd8e0e | 77 | } |
tony1tf | 0:8c725fbd8e0e | 78 | |
tony1tf | 0:8c725fbd8e0e | 79 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 80 | |
tony1tf | 0:8c725fbd8e0e | 81 | void Morse_Code::Sound_Off ( void ) { |
tony1tf | 0:8c725fbd8e0e | 82 | |
tony1tf | 0:8c725fbd8e0e | 83 | Morse_Flag._Sound = 0; |
tony1tf | 0:8c725fbd8e0e | 84 | |
tony1tf | 0:8c725fbd8e0e | 85 | } |
tony1tf | 0:8c725fbd8e0e | 86 | |
tony1tf | 0:8c725fbd8e0e | 87 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 88 | |
tony1tf | 0:8c725fbd8e0e | 89 | void Morse_Code::Sound_Toggle ( void ) { |
tony1tf | 0:8c725fbd8e0e | 90 | |
tony1tf | 0:8c725fbd8e0e | 91 | Morse_Flag._Sound ^= 1; |
tony1tf | 0:8c725fbd8e0e | 92 | |
tony1tf | 0:8c725fbd8e0e | 93 | } |
tony1tf | 0:8c725fbd8e0e | 94 | |
tony1tf | 0:8c725fbd8e0e | 95 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 96 | |
tony1tf | 0:8c725fbd8e0e | 97 | void Morse_Code::Practice_On ( void ) { |
tony1tf | 0:8c725fbd8e0e | 98 | |
tony1tf | 0:8c725fbd8e0e | 99 | Morse_Flag._Practice = 1; |
tony1tf | 0:8c725fbd8e0e | 100 | |
tony1tf | 0:8c725fbd8e0e | 101 | } |
tony1tf | 0:8c725fbd8e0e | 102 | |
tony1tf | 0:8c725fbd8e0e | 103 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 104 | |
tony1tf | 0:8c725fbd8e0e | 105 | void Morse_Code::Practice_Off ( void ) { |
tony1tf | 0:8c725fbd8e0e | 106 | |
tony1tf | 0:8c725fbd8e0e | 107 | Morse_Flag._Practice = 0; |
tony1tf | 0:8c725fbd8e0e | 108 | |
tony1tf | 0:8c725fbd8e0e | 109 | } |
tony1tf | 0:8c725fbd8e0e | 110 | |
tony1tf | 0:8c725fbd8e0e | 111 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 112 | |
tony1tf | 0:8c725fbd8e0e | 113 | void Morse_Code::Practice_Toggle ( void ) { |
tony1tf | 0:8c725fbd8e0e | 114 | |
tony1tf | 0:8c725fbd8e0e | 115 | Morse_Flag._Practice ^= 1; |
tony1tf | 0:8c725fbd8e0e | 116 | |
tony1tf | 0:8c725fbd8e0e | 117 | // Serial.print ( Morse_Flag._Practice ); |
tony1tf | 0:8c725fbd8e0e | 118 | |
tony1tf | 0:8c725fbd8e0e | 119 | } |
tony1tf | 0:8c725fbd8e0e | 120 | |
tony1tf | 0:8c725fbd8e0e | 121 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 122 | |
tony1tf | 0:8c725fbd8e0e | 123 | int Morse_Code::get_Practice ( void ) { |
tony1tf | 0:8c725fbd8e0e | 124 | |
tony1tf | 0:8c725fbd8e0e | 125 | return Morse_Flag._Practice; |
tony1tf | 0:8c725fbd8e0e | 126 | |
tony1tf | 0:8c725fbd8e0e | 127 | } |
tony1tf | 0:8c725fbd8e0e | 128 | |
tony1tf | 0:8c725fbd8e0e | 129 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 130 | |
tony1tf | 0:8c725fbd8e0e | 131 | void Morse_Code::set_Tone ( int frequency ) { |
tony1tf | 0:8c725fbd8e0e | 132 | |
tony1tf | 0:8c725fbd8e0e | 133 | _Tone_Frequency = frequency; |
tony1tf | 0:8c725fbd8e0e | 134 | |
tony1tf | 0:8c725fbd8e0e | 135 | } |
tony1tf | 0:8c725fbd8e0e | 136 | |
tony1tf | 0:8c725fbd8e0e | 137 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 138 | |
tony1tf | 0:8c725fbd8e0e | 139 | int Morse_Code::get_Tone ( ) { |
tony1tf | 0:8c725fbd8e0e | 140 | |
tony1tf | 0:8c725fbd8e0e | 141 | return _Tone_Frequency; |
tony1tf | 0:8c725fbd8e0e | 142 | |
tony1tf | 0:8c725fbd8e0e | 143 | } |
tony1tf | 0:8c725fbd8e0e | 144 | |
tony1tf | 0:8c725fbd8e0e | 145 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 146 | |
tony1tf | 0:8c725fbd8e0e | 147 | void Morse_Code::Tone_Adjust ( int delta, int limit ) { |
tony1tf | 0:8c725fbd8e0e | 148 | |
tony1tf | 0:8c725fbd8e0e | 149 | Adjust ( &_Tone_Frequency, delta, limit ); |
tony1tf | 0:8c725fbd8e0e | 150 | |
tony1tf | 0:8c725fbd8e0e | 151 | } |
tony1tf | 0:8c725fbd8e0e | 152 | |
tony1tf | 0:8c725fbd8e0e | 153 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 154 | |
tony1tf | 0:8c725fbd8e0e | 155 | void Morse_Code::set_WPM ( float WPM_Speed ) { |
tony1tf | 0:8c725fbd8e0e | 156 | |
tony1tf | 0:8c725fbd8e0e | 157 | _WPM_Speed = WPM_Speed; |
tony1tf | 0:8c725fbd8e0e | 158 | |
tony1tf | 0:8c725fbd8e0e | 159 | } |
tony1tf | 0:8c725fbd8e0e | 160 | |
tony1tf | 0:8c725fbd8e0e | 161 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 162 | |
tony1tf | 0:8c725fbd8e0e | 163 | float Morse_Code::get_WPM ( ) { |
tony1tf | 0:8c725fbd8e0e | 164 | |
tony1tf | 0:8c725fbd8e0e | 165 | return _WPM_Speed; |
tony1tf | 0:8c725fbd8e0e | 166 | |
tony1tf | 0:8c725fbd8e0e | 167 | } |
tony1tf | 0:8c725fbd8e0e | 168 | |
tony1tf | 0:8c725fbd8e0e | 169 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 170 | |
tony1tf | 0:8c725fbd8e0e | 171 | void Morse_Code::WPM_Adjust ( float delta, float limit ) { |
tony1tf | 0:8c725fbd8e0e | 172 | |
tony1tf | 0:8c725fbd8e0e | 173 | Adjust ( &_WPM_Speed, delta, limit ); |
tony1tf | 0:8c725fbd8e0e | 174 | |
tony1tf | 0:8c725fbd8e0e | 175 | Calculate_Morse_Timing ( _WPM_Speed, _WPM_Character ); |
tony1tf | 0:8c725fbd8e0e | 176 | |
tony1tf | 0:8c725fbd8e0e | 177 | } |
tony1tf | 0:8c725fbd8e0e | 178 | |
tony1tf | 0:8c725fbd8e0e | 179 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 180 | |
tony1tf | 0:8c725fbd8e0e | 181 | char Morse_Code::Morse ( char ASCII ) { |
tony1tf | 0:8c725fbd8e0e | 182 | |
tony1tf | 0:8c725fbd8e0e | 183 | switch ( ASCII ) { |
tony1tf | 0:8c725fbd8e0e | 184 | |
tony1tf | 0:8c725fbd8e0e | 185 | case 'a': |
tony1tf | 0:8c725fbd8e0e | 186 | case 'A': |
tony1tf | 0:8c725fbd8e0e | 187 | |
tony1tf | 0:8c725fbd8e0e | 188 | return 0x05; // B'0000 0101' ;A |
tony1tf | 0:8c725fbd8e0e | 189 | |
tony1tf | 0:8c725fbd8e0e | 190 | case 'b': |
tony1tf | 0:8c725fbd8e0e | 191 | case 'B': |
tony1tf | 0:8c725fbd8e0e | 192 | |
tony1tf | 0:8c725fbd8e0e | 193 | return 0x18; // B'0001 1000' ;B |
tony1tf | 0:8c725fbd8e0e | 194 | |
tony1tf | 0:8c725fbd8e0e | 195 | case 'c': |
tony1tf | 0:8c725fbd8e0e | 196 | case 'C': |
tony1tf | 0:8c725fbd8e0e | 197 | |
tony1tf | 0:8c725fbd8e0e | 198 | return 0x1A; // B'0001 1010' ;C |
tony1tf | 0:8c725fbd8e0e | 199 | |
tony1tf | 0:8c725fbd8e0e | 200 | case 'd': |
tony1tf | 0:8c725fbd8e0e | 201 | case 'D': |
tony1tf | 0:8c725fbd8e0e | 202 | |
tony1tf | 0:8c725fbd8e0e | 203 | return 0x0C; // B'0000 1100' ;D |
tony1tf | 0:8c725fbd8e0e | 204 | |
tony1tf | 0:8c725fbd8e0e | 205 | case 'e': |
tony1tf | 0:8c725fbd8e0e | 206 | case 'E': |
tony1tf | 0:8c725fbd8e0e | 207 | |
tony1tf | 0:8c725fbd8e0e | 208 | return 0x02; // B'0000 0010' ;E |
tony1tf | 0:8c725fbd8e0e | 209 | |
tony1tf | 0:8c725fbd8e0e | 210 | case 'f': |
tony1tf | 0:8c725fbd8e0e | 211 | case 'F': |
tony1tf | 0:8c725fbd8e0e | 212 | |
tony1tf | 0:8c725fbd8e0e | 213 | return 0x12; // B'0001 0010' ;F |
tony1tf | 0:8c725fbd8e0e | 214 | |
tony1tf | 0:8c725fbd8e0e | 215 | case 'g': |
tony1tf | 0:8c725fbd8e0e | 216 | case 'G': |
tony1tf | 0:8c725fbd8e0e | 217 | |
tony1tf | 0:8c725fbd8e0e | 218 | return 0x0E; // B'0000 1110' ;G |
tony1tf | 0:8c725fbd8e0e | 219 | |
tony1tf | 0:8c725fbd8e0e | 220 | case 'h': |
tony1tf | 0:8c725fbd8e0e | 221 | case 'H': |
tony1tf | 0:8c725fbd8e0e | 222 | |
tony1tf | 0:8c725fbd8e0e | 223 | return 0x10; // B'0001 0000' ;H |
tony1tf | 0:8c725fbd8e0e | 224 | |
tony1tf | 0:8c725fbd8e0e | 225 | case 'i': |
tony1tf | 0:8c725fbd8e0e | 226 | case 'I': |
tony1tf | 0:8c725fbd8e0e | 227 | |
tony1tf | 0:8c725fbd8e0e | 228 | return 0x04; // B'0000 0100' ;I |
tony1tf | 0:8c725fbd8e0e | 229 | |
tony1tf | 0:8c725fbd8e0e | 230 | case 'j': |
tony1tf | 0:8c725fbd8e0e | 231 | case 'J': |
tony1tf | 0:8c725fbd8e0e | 232 | |
tony1tf | 0:8c725fbd8e0e | 233 | return 0x17; // B'0001 0111' ;J |
tony1tf | 0:8c725fbd8e0e | 234 | |
tony1tf | 0:8c725fbd8e0e | 235 | case 'k': |
tony1tf | 0:8c725fbd8e0e | 236 | case 'K': |
tony1tf | 0:8c725fbd8e0e | 237 | |
tony1tf | 0:8c725fbd8e0e | 238 | return 0x0D; // B'0000 1101' ;K |
tony1tf | 0:8c725fbd8e0e | 239 | |
tony1tf | 0:8c725fbd8e0e | 240 | case 'l': |
tony1tf | 0:8c725fbd8e0e | 241 | case 'L': |
tony1tf | 0:8c725fbd8e0e | 242 | |
tony1tf | 0:8c725fbd8e0e | 243 | return 0x14; // B'0001 0100' ;L |
tony1tf | 0:8c725fbd8e0e | 244 | |
tony1tf | 0:8c725fbd8e0e | 245 | case 'm': |
tony1tf | 0:8c725fbd8e0e | 246 | case 'M': |
tony1tf | 0:8c725fbd8e0e | 247 | |
tony1tf | 0:8c725fbd8e0e | 248 | return 0x07; // B'0000 0111' ;M |
tony1tf | 0:8c725fbd8e0e | 249 | |
tony1tf | 0:8c725fbd8e0e | 250 | case 'n': |
tony1tf | 0:8c725fbd8e0e | 251 | case 'N': |
tony1tf | 0:8c725fbd8e0e | 252 | |
tony1tf | 0:8c725fbd8e0e | 253 | return 0x06; // B'0000 0110' ;N |
tony1tf | 0:8c725fbd8e0e | 254 | |
tony1tf | 0:8c725fbd8e0e | 255 | case 'o': |
tony1tf | 0:8c725fbd8e0e | 256 | case 'O': |
tony1tf | 0:8c725fbd8e0e | 257 | |
tony1tf | 0:8c725fbd8e0e | 258 | return 0x0F; // B'0000 1111' ;O |
tony1tf | 0:8c725fbd8e0e | 259 | |
tony1tf | 0:8c725fbd8e0e | 260 | case 'p': |
tony1tf | 0:8c725fbd8e0e | 261 | case 'P': |
tony1tf | 0:8c725fbd8e0e | 262 | |
tony1tf | 0:8c725fbd8e0e | 263 | return 0x16; // B'0001 0110' ;P |
tony1tf | 0:8c725fbd8e0e | 264 | |
tony1tf | 0:8c725fbd8e0e | 265 | case 'q': |
tony1tf | 0:8c725fbd8e0e | 266 | case 'Q': |
tony1tf | 0:8c725fbd8e0e | 267 | |
tony1tf | 0:8c725fbd8e0e | 268 | return 0x1D; // B'0001 1101' ;Q |
tony1tf | 0:8c725fbd8e0e | 269 | |
tony1tf | 0:8c725fbd8e0e | 270 | case 'r': |
tony1tf | 0:8c725fbd8e0e | 271 | case 'R': |
tony1tf | 0:8c725fbd8e0e | 272 | |
tony1tf | 0:8c725fbd8e0e | 273 | return 0x0A; // B'0000 1010' ;R |
tony1tf | 0:8c725fbd8e0e | 274 | |
tony1tf | 0:8c725fbd8e0e | 275 | case 's': |
tony1tf | 0:8c725fbd8e0e | 276 | case 'S': |
tony1tf | 0:8c725fbd8e0e | 277 | |
tony1tf | 0:8c725fbd8e0e | 278 | return 0x08; // B'0000 1000' ;S |
tony1tf | 0:8c725fbd8e0e | 279 | |
tony1tf | 0:8c725fbd8e0e | 280 | case 't': |
tony1tf | 0:8c725fbd8e0e | 281 | case 'T': |
tony1tf | 0:8c725fbd8e0e | 282 | |
tony1tf | 0:8c725fbd8e0e | 283 | return 0x03; // B'0000 0011' ;T |
tony1tf | 0:8c725fbd8e0e | 284 | |
tony1tf | 0:8c725fbd8e0e | 285 | case 'u': |
tony1tf | 0:8c725fbd8e0e | 286 | case 'U': |
tony1tf | 0:8c725fbd8e0e | 287 | |
tony1tf | 0:8c725fbd8e0e | 288 | return 0x09; // B'0000 1001' ;U |
tony1tf | 0:8c725fbd8e0e | 289 | |
tony1tf | 0:8c725fbd8e0e | 290 | case 'v': |
tony1tf | 0:8c725fbd8e0e | 291 | case 'V': |
tony1tf | 0:8c725fbd8e0e | 292 | |
tony1tf | 0:8c725fbd8e0e | 293 | return 0x11; // B'0001 0001' ;V |
tony1tf | 0:8c725fbd8e0e | 294 | |
tony1tf | 0:8c725fbd8e0e | 295 | case 'w': |
tony1tf | 0:8c725fbd8e0e | 296 | case 'W': |
tony1tf | 0:8c725fbd8e0e | 297 | |
tony1tf | 0:8c725fbd8e0e | 298 | return 0x0B; // B'0000 1011' ;W |
tony1tf | 0:8c725fbd8e0e | 299 | |
tony1tf | 0:8c725fbd8e0e | 300 | case 'x': |
tony1tf | 0:8c725fbd8e0e | 301 | case 'X': |
tony1tf | 0:8c725fbd8e0e | 302 | |
tony1tf | 0:8c725fbd8e0e | 303 | return 0x19; // B'0001 1001' ;X |
tony1tf | 0:8c725fbd8e0e | 304 | |
tony1tf | 0:8c725fbd8e0e | 305 | case 'y': |
tony1tf | 0:8c725fbd8e0e | 306 | case 'Y': |
tony1tf | 0:8c725fbd8e0e | 307 | |
tony1tf | 0:8c725fbd8e0e | 308 | return 0x1B; // B'0001 1011' ;Y |
tony1tf | 0:8c725fbd8e0e | 309 | |
tony1tf | 0:8c725fbd8e0e | 310 | case 'z': |
tony1tf | 0:8c725fbd8e0e | 311 | case 'Z': |
tony1tf | 0:8c725fbd8e0e | 312 | |
tony1tf | 0:8c725fbd8e0e | 313 | return 0x1C; // B'0001 1100' ;Z |
tony1tf | 0:8c725fbd8e0e | 314 | |
tony1tf | 0:8c725fbd8e0e | 315 | case '1': |
tony1tf | 0:8c725fbd8e0e | 316 | |
tony1tf | 0:8c725fbd8e0e | 317 | return 0x2F; // B'0010 1111' ;1 |
tony1tf | 0:8c725fbd8e0e | 318 | |
tony1tf | 0:8c725fbd8e0e | 319 | case '2': |
tony1tf | 0:8c725fbd8e0e | 320 | |
tony1tf | 0:8c725fbd8e0e | 321 | return 0x27; // B'0010 0111' ;2 |
tony1tf | 0:8c725fbd8e0e | 322 | |
tony1tf | 0:8c725fbd8e0e | 323 | case '3': |
tony1tf | 0:8c725fbd8e0e | 324 | |
tony1tf | 0:8c725fbd8e0e | 325 | return 0x23; // B'0010 0011' ;3 |
tony1tf | 0:8c725fbd8e0e | 326 | |
tony1tf | 0:8c725fbd8e0e | 327 | case '4': |
tony1tf | 0:8c725fbd8e0e | 328 | |
tony1tf | 0:8c725fbd8e0e | 329 | return 0x21; // B'0010 0001' ;4 |
tony1tf | 0:8c725fbd8e0e | 330 | |
tony1tf | 0:8c725fbd8e0e | 331 | case '5': |
tony1tf | 0:8c725fbd8e0e | 332 | |
tony1tf | 0:8c725fbd8e0e | 333 | return 0x20; // B'0010 0000' ;5 |
tony1tf | 0:8c725fbd8e0e | 334 | |
tony1tf | 0:8c725fbd8e0e | 335 | case '6': |
tony1tf | 0:8c725fbd8e0e | 336 | |
tony1tf | 0:8c725fbd8e0e | 337 | return 0x30; // B'0011 0000' ;6 |
tony1tf | 0:8c725fbd8e0e | 338 | |
tony1tf | 0:8c725fbd8e0e | 339 | case '7': |
tony1tf | 0:8c725fbd8e0e | 340 | |
tony1tf | 0:8c725fbd8e0e | 341 | return 0x38; // B'0011 1000' ;7 |
tony1tf | 0:8c725fbd8e0e | 342 | |
tony1tf | 0:8c725fbd8e0e | 343 | case '8': |
tony1tf | 0:8c725fbd8e0e | 344 | |
tony1tf | 0:8c725fbd8e0e | 345 | return 0x3C; // B'0011 1100' ;8 |
tony1tf | 0:8c725fbd8e0e | 346 | |
tony1tf | 0:8c725fbd8e0e | 347 | case '9': |
tony1tf | 0:8c725fbd8e0e | 348 | |
tony1tf | 0:8c725fbd8e0e | 349 | return 0x3E; // B'0011 1110' ;9 |
tony1tf | 0:8c725fbd8e0e | 350 | |
tony1tf | 0:8c725fbd8e0e | 351 | case '0': |
tony1tf | 0:8c725fbd8e0e | 352 | |
tony1tf | 0:8c725fbd8e0e | 353 | return 0x3F; // B'0011 1111' ;0 |
tony1tf | 0:8c725fbd8e0e | 354 | |
tony1tf | 0:8c725fbd8e0e | 355 | case '.': |
tony1tf | 0:8c725fbd8e0e | 356 | |
tony1tf | 0:8c725fbd8e0e | 357 | return 0x55; // B'0101 0101' ;. |
tony1tf | 0:8c725fbd8e0e | 358 | |
tony1tf | 0:8c725fbd8e0e | 359 | case ',': |
tony1tf | 0:8c725fbd8e0e | 360 | |
tony1tf | 0:8c725fbd8e0e | 361 | return 0x73; // B'0111 0011' ;, |
tony1tf | 0:8c725fbd8e0e | 362 | |
tony1tf | 0:8c725fbd8e0e | 363 | case ';': |
tony1tf | 0:8c725fbd8e0e | 364 | |
tony1tf | 0:8c725fbd8e0e | 365 | return 0x6A; // B'0110 1010' ;; |
tony1tf | 0:8c725fbd8e0e | 366 | |
tony1tf | 0:8c725fbd8e0e | 367 | case ':': |
tony1tf | 0:8c725fbd8e0e | 368 | |
tony1tf | 0:8c725fbd8e0e | 369 | return 0x78; // B'0111 1000' ;: |
tony1tf | 0:8c725fbd8e0e | 370 | |
tony1tf | 0:8c725fbd8e0e | 371 | case 0x27: |
tony1tf | 0:8c725fbd8e0e | 372 | |
tony1tf | 0:8c725fbd8e0e | 373 | return 0x5E; // B'0101 1110' ;' |
tony1tf | 0:8c725fbd8e0e | 374 | |
tony1tf | 0:8c725fbd8e0e | 375 | case 0x22: |
tony1tf | 0:8c725fbd8e0e | 376 | |
tony1tf | 0:8c725fbd8e0e | 377 | return 0x52; // B'0101 0010' ;" |
tony1tf | 0:8c725fbd8e0e | 378 | |
tony1tf | 0:8c725fbd8e0e | 379 | case '/': |
tony1tf | 0:8c725fbd8e0e | 380 | |
tony1tf | 0:8c725fbd8e0e | 381 | return 0x32; // B'0011 0010' ;/ |
tony1tf | 0:8c725fbd8e0e | 382 | |
tony1tf | 0:8c725fbd8e0e | 383 | case '?': |
tony1tf | 0:8c725fbd8e0e | 384 | |
tony1tf | 0:8c725fbd8e0e | 385 | return 0x4C; // B'0100 1100' ;? |
tony1tf | 0:8c725fbd8e0e | 386 | |
tony1tf | 0:8c725fbd8e0e | 387 | case '-': |
tony1tf | 0:8c725fbd8e0e | 388 | |
tony1tf | 0:8c725fbd8e0e | 389 | return 0x61; // B'0110 0001' ;- |
tony1tf | 0:8c725fbd8e0e | 390 | |
tony1tf | 0:8c725fbd8e0e | 391 | case '_': |
tony1tf | 0:8c725fbd8e0e | 392 | |
tony1tf | 0:8c725fbd8e0e | 393 | return 0x4D; // B'0100 1101' ;_ |
tony1tf | 0:8c725fbd8e0e | 394 | |
tony1tf | 0:8c725fbd8e0e | 395 | case '=': |
tony1tf | 0:8c725fbd8e0e | 396 | |
tony1tf | 0:8c725fbd8e0e | 397 | return 0x31; // B'0011 0001' ;= |
tony1tf | 0:8c725fbd8e0e | 398 | |
tony1tf | 0:8c725fbd8e0e | 399 | case '+': |
tony1tf | 0:8c725fbd8e0e | 400 | |
tony1tf | 0:8c725fbd8e0e | 401 | return 0x2A; // B'0010 1010' ;+ |
tony1tf | 0:8c725fbd8e0e | 402 | |
tony1tf | 0:8c725fbd8e0e | 403 | case '!': |
tony1tf | 0:8c725fbd8e0e | 404 | |
tony1tf | 0:8c725fbd8e0e | 405 | return 0x22; // B'0010 0010' ;! |
tony1tf | 0:8c725fbd8e0e | 406 | |
tony1tf | 0:8c725fbd8e0e | 407 | case '@': |
tony1tf | 0:8c725fbd8e0e | 408 | |
tony1tf | 0:8c725fbd8e0e | 409 | return 0x5A; // B'0101 1010' ;@ |
tony1tf | 0:8c725fbd8e0e | 410 | |
tony1tf | 0:8c725fbd8e0e | 411 | case '#': |
tony1tf | 0:8c725fbd8e0e | 412 | |
tony1tf | 0:8c725fbd8e0e | 413 | return 0x54; // B'0101 0100' ;# |
tony1tf | 0:8c725fbd8e0e | 414 | |
tony1tf | 0:8c725fbd8e0e | 415 | case '$': |
tony1tf | 0:8c725fbd8e0e | 416 | |
tony1tf | 0:8c725fbd8e0e | 417 | return 0x89; // B'1000 1001' ;$ |
tony1tf | 0:8c725fbd8e0e | 418 | |
tony1tf | 0:8c725fbd8e0e | 419 | case '%': |
tony1tf | 0:8c725fbd8e0e | 420 | |
tony1tf | 0:8c725fbd8e0e | 421 | return 0x35; // B'0011 0101' ;% |
tony1tf | 0:8c725fbd8e0e | 422 | |
tony1tf | 0:8c725fbd8e0e | 423 | case '^': |
tony1tf | 0:8c725fbd8e0e | 424 | |
tony1tf | 0:8c725fbd8e0e | 425 | return 0x0D; // B'0000 1101' ;^ |
tony1tf | 0:8c725fbd8e0e | 426 | |
tony1tf | 0:8c725fbd8e0e | 427 | case '&': |
tony1tf | 0:8c725fbd8e0e | 428 | |
tony1tf | 0:8c725fbd8e0e | 429 | return 0x28; // B'0010 1000' ;& |
tony1tf | 0:8c725fbd8e0e | 430 | |
tony1tf | 0:8c725fbd8e0e | 431 | case '*': |
tony1tf | 0:8c725fbd8e0e | 432 | |
tony1tf | 0:8c725fbd8e0e | 433 | return 0x45; // B'0100 0101' ;* |
tony1tf | 0:8c725fbd8e0e | 434 | |
tony1tf | 0:8c725fbd8e0e | 435 | case '(': |
tony1tf | 0:8c725fbd8e0e | 436 | |
tony1tf | 0:8c725fbd8e0e | 437 | return 0x36; // B'0011 0110' ;( |
tony1tf | 0:8c725fbd8e0e | 438 | |
tony1tf | 0:8c725fbd8e0e | 439 | case ')': |
tony1tf | 0:8c725fbd8e0e | 440 | |
tony1tf | 0:8c725fbd8e0e | 441 | return 0x6D; // B'0110 1101' ;) |
tony1tf | 0:8c725fbd8e0e | 442 | |
tony1tf | 0:8c725fbd8e0e | 443 | case 0x09: |
tony1tf | 0:8c725fbd8e0e | 444 | |
tony1tf | 0:8c725fbd8e0e | 445 | return 0x54; // B'0101 0100' ;TAB |
tony1tf | 0:8c725fbd8e0e | 446 | |
tony1tf | 0:8c725fbd8e0e | 447 | case 0x08: |
tony1tf | 0:8c725fbd8e0e | 448 | |
tony1tf | 0:8c725fbd8e0e | 449 | return 0x80; // B'1000 0000' ;Backspace |
tony1tf | 0:8c725fbd8e0e | 450 | |
tony1tf | 0:8c725fbd8e0e | 451 | case ' ': |
tony1tf | 0:8c725fbd8e0e | 452 | |
tony1tf | 0:8c725fbd8e0e | 453 | return 0x01; // B'1000 0000' ;space |
tony1tf | 0:8c725fbd8e0e | 454 | |
tony1tf | 0:8c725fbd8e0e | 455 | default: |
tony1tf | 0:8c725fbd8e0e | 456 | |
tony1tf | 0:8c725fbd8e0e | 457 | return 0x01; |
tony1tf | 0:8c725fbd8e0e | 458 | |
tony1tf | 0:8c725fbd8e0e | 459 | } |
tony1tf | 0:8c725fbd8e0e | 460 | |
tony1tf | 0:8c725fbd8e0e | 461 | } |
tony1tf | 0:8c725fbd8e0e | 462 | |
tony1tf | 0:8c725fbd8e0e | 463 | //=================================================================== |
tony1tf | 0:8c725fbd8e0e | 464 | |
tony1tf | 0:8c725fbd8e0e | 465 | void Morse_Code::Send_Morse ( char Morse ) { |
tony1tf | 0:8c725fbd8e0e | 466 | |
tony1tf | 0:8c725fbd8e0e | 467 | char bit_counter = 8; |
tony1tf | 0:8c725fbd8e0e | 468 | |
tony1tf | 0:8c725fbd8e0e | 469 | while ( !( Morse & 0x80 ) ) { |
tony1tf | 0:8c725fbd8e0e | 470 | |
tony1tf | 0:8c725fbd8e0e | 471 | Morse <<= 1; |
tony1tf | 0:8c725fbd8e0e | 472 | |
tony1tf | 0:8c725fbd8e0e | 473 | --bit_counter; |
tony1tf | 0:8c725fbd8e0e | 474 | |
tony1tf | 0:8c725fbd8e0e | 475 | } |
tony1tf | 0:8c725fbd8e0e | 476 | |
tony1tf | 0:8c725fbd8e0e | 477 | Morse_Flag.last_bit = 0; |
tony1tf | 0:8c725fbd8e0e | 478 | |
tony1tf | 0:8c725fbd8e0e | 479 | while ( --bit_counter ) { |
tony1tf | 0:8c725fbd8e0e | 480 | |
tony1tf | 0:8c725fbd8e0e | 481 | if ( bit_counter == 1 ) Morse_Flag.last_bit = 1; |
tony1tf | 0:8c725fbd8e0e | 482 | |
tony1tf | 0:8c725fbd8e0e | 483 | if ( ( Morse <<= 1 ) & 0x80 ) dah(); |
tony1tf | 0:8c725fbd8e0e | 484 | |
tony1tf | 0:8c725fbd8e0e | 485 | else dit(); |
tony1tf | 0:8c725fbd8e0e | 486 | |
tony1tf | 0:8c725fbd8e0e | 487 | if ( !Morse_Flag.last_bit ) wait ( u ); |
tony1tf | 0:8c725fbd8e0e | 488 | |
tony1tf | 0:8c725fbd8e0e | 489 | else if ( Morse_Flag.last_char ) wait ( tw ); |
tony1tf | 0:8c725fbd8e0e | 490 | |
tony1tf | 0:8c725fbd8e0e | 491 | else wait ( tc ); |
tony1tf | 0:8c725fbd8e0e | 492 | |
tony1tf | 0:8c725fbd8e0e | 493 | } |
tony1tf | 0:8c725fbd8e0e | 494 | |
tony1tf | 0:8c725fbd8e0e | 495 | } |
tony1tf | 0:8c725fbd8e0e | 496 | |
tony1tf | 0:8c725fbd8e0e | 497 | //=================================================================== |
tony1tf | 0:8c725fbd8e0e | 498 | |
tony1tf | 0:8c725fbd8e0e | 499 | char Morse_Code::Random_Code ( void ) { |
tony1tf | 0:8c725fbd8e0e | 500 | |
tony1tf | 0:8c725fbd8e0e | 501 | char ascii; |
tony1tf | 0:8c725fbd8e0e | 502 | |
tony1tf | 0:8c725fbd8e0e | 503 | static char count; |
tony1tf | 0:8c725fbd8e0e | 504 | |
tony1tf | 0:8c725fbd8e0e | 505 | ascii = 32 + rand () % 95; |
tony1tf | 0:8c725fbd8e0e | 506 | |
tony1tf | 0:8c725fbd8e0e | 507 | Send_Morse ( Morse ( ascii ) ); |
tony1tf | 0:8c725fbd8e0e | 508 | |
tony1tf | 0:8c725fbd8e0e | 509 | if ( ( count++ ) % 5 == 0 ) Morse_Flag.last_char = 1; |
tony1tf | 0:8c725fbd8e0e | 510 | |
tony1tf | 0:8c725fbd8e0e | 511 | else Morse_Flag.last_char = 0; |
tony1tf | 0:8c725fbd8e0e | 512 | |
tony1tf | 0:8c725fbd8e0e | 513 | return ascii; |
tony1tf | 0:8c725fbd8e0e | 514 | |
tony1tf | 0:8c725fbd8e0e | 515 | } |
tony1tf | 0:8c725fbd8e0e | 516 | |
tony1tf | 0:8c725fbd8e0e | 517 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 518 | // The ARRL Morse Transmission Timing Standard |
tony1tf | 0:8c725fbd8e0e | 519 | |
tony1tf | 0:8c725fbd8e0e | 520 | void Morse_Code::Calculate_Morse_Timing ( float s, float c ) { // In seconds for wait function |
tony1tf | 0:8c725fbd8e0e | 521 | |
tony1tf | 0:8c725fbd8e0e | 522 | if ( s >= 18.0 ) { |
tony1tf | 0:8c725fbd8e0e | 523 | |
tony1tf | 0:8c725fbd8e0e | 524 | c = s; |
tony1tf | 0:8c725fbd8e0e | 525 | |
tony1tf | 0:8c725fbd8e0e | 526 | u = 1.2 / c; |
tony1tf | 0:8c725fbd8e0e | 527 | |
tony1tf | 0:8c725fbd8e0e | 528 | tc = 3.0 * u; |
tony1tf | 0:8c725fbd8e0e | 529 | |
tony1tf | 0:8c725fbd8e0e | 530 | tw = 7.0 * u; |
tony1tf | 0:8c725fbd8e0e | 531 | |
tony1tf | 0:8c725fbd8e0e | 532 | } |
tony1tf | 0:8c725fbd8e0e | 533 | |
tony1tf | 0:8c725fbd8e0e | 534 | else { |
tony1tf | 0:8c725fbd8e0e | 535 | |
tony1tf | 0:8c725fbd8e0e | 536 | u = 1.2 / c; |
tony1tf | 0:8c725fbd8e0e | 537 | |
tony1tf | 0:8c725fbd8e0e | 538 | ta = ( 60.0 * c - 37.2 * s ) / ( s * c ); |
tony1tf | 0:8c725fbd8e0e | 539 | |
tony1tf | 0:8c725fbd8e0e | 540 | tc = 3.0 * ta / 19.0; |
tony1tf | 0:8c725fbd8e0e | 541 | |
tony1tf | 0:8c725fbd8e0e | 542 | tw = 7.0 * ta / 19.0; |
tony1tf | 0:8c725fbd8e0e | 543 | |
tony1tf | 0:8c725fbd8e0e | 544 | } |
tony1tf | 0:8c725fbd8e0e | 545 | |
tony1tf | 0:8c725fbd8e0e | 546 | } |
tony1tf | 0:8c725fbd8e0e | 547 | |
tony1tf | 0:8c725fbd8e0e | 548 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 549 | |
tony1tf | 0:8c725fbd8e0e | 550 | void Morse_Code::dit ( ) { |
tony1tf | 0:8c725fbd8e0e | 551 | |
tony1tf | 2:260128ae5746 | 552 | if ( _colour == 1 ) blue = on; |
tony1tf | 2:260128ae5746 | 553 | if ( _colour == 2 ) red = on; |
tony1tf | 2:260128ae5746 | 554 | if ( _colour == 3 ) green = on; |
tony1tf | 2:260128ae5746 | 555 | if ( _colour == 4 ) blue = on red = on green = on ; |
tony1tf | 0:8c725fbd8e0e | 556 | |
tony1tf | 1:ba9c803c7596 | 557 | Tone ( _Tone_Frequency, u, 1.0 ); |
tony1tf | 0:8c725fbd8e0e | 558 | |
tony1tf | 2:260128ae5746 | 559 | blue = off red = off green = off ; |
tony1tf | 0:8c725fbd8e0e | 560 | |
tony1tf | 0:8c725fbd8e0e | 561 | } |
tony1tf | 0:8c725fbd8e0e | 562 | |
tony1tf | 0:8c725fbd8e0e | 563 | //============================================================== |
tony1tf | 0:8c725fbd8e0e | 564 | |
tony1tf | 0:8c725fbd8e0e | 565 | void Morse_Code::dah ( ) { |
tony1tf | 0:8c725fbd8e0e | 566 | |
tony1tf | 2:260128ae5746 | 567 | if ( _colour == 1 ) blue = on; |
tony1tf | 2:260128ae5746 | 568 | if ( _colour == 2 ) red = on; |
tony1tf | 2:260128ae5746 | 569 | if ( _colour == 3 ) green = on; |
tony1tf | 2:260128ae5746 | 570 | if ( _colour == 4 ) blue = on red = on green = on ; |
tony1tf | 0:8c725fbd8e0e | 571 | |
tony1tf | 1:ba9c803c7596 | 572 | Tone ( _Tone_Frequency, u, 3.0 ); |
tony1tf | 0:8c725fbd8e0e | 573 | |
tony1tf | 2:260128ae5746 | 574 | blue = off red = off green = off ; |
tony1tf | 0:8c725fbd8e0e | 575 | |
tony1tf | 0:8c725fbd8e0e | 576 | } |
tony1tf | 0:8c725fbd8e0e | 577 | |
tony1tf | 0:8c725fbd8e0e | 578 | //============================================================= |
tony1tf | 0:8c725fbd8e0e | 579 | |
tony1tf | 1:ba9c803c7596 | 580 | void Morse_Code::Tone ( int freq_factor, float duration, float multiplier ) { |
tony1tf | 0:8c725fbd8e0e | 581 | |
tony1tf | 0:8c725fbd8e0e | 582 | Timer timer; |
tony1tf | 0:8c725fbd8e0e | 583 | |
tony1tf | 0:8c725fbd8e0e | 584 | char i = 0; |
tony1tf | 1:ba9c803c7596 | 585 | float t; |
tony1tf | 0:8c725fbd8e0e | 586 | |
tony1tf | 0:8c725fbd8e0e | 587 | unsigned int delay; |
tony1tf | 1:ba9c803c7596 | 588 | float amplitude = 0; |
tony1tf | 0:8c725fbd8e0e | 589 | |
tony1tf | 0:8c725fbd8e0e | 590 | timer.start(); |
tony1tf | 0:8c725fbd8e0e | 591 | |
tony1tf | 0:8c725fbd8e0e | 592 | timer.reset(); |
tony1tf | 0:8c725fbd8e0e | 593 | |
tony1tf | 0:8c725fbd8e0e | 594 | do { |
tony1tf | 0:8c725fbd8e0e | 595 | |
tony1tf | 0:8c725fbd8e0e | 596 | for ( i = 0; i < 32; i++ ) { |
tony1tf | 0:8c725fbd8e0e | 597 | |
tony1tf | 2:260128ae5746 | 598 | piezo = sine_wave [ i ] * amplitude + 0.4; |
tony1tf | 0:8c725fbd8e0e | 599 | |
tony1tf | 0:8c725fbd8e0e | 600 | for ( delay = 0; delay < freq_factor; delay++ ); |
tony1tf | 0:8c725fbd8e0e | 601 | |
tony1tf | 1:ba9c803c7596 | 602 | } t = timer.read() ; |
tony1tf | 2:260128ae5746 | 603 | if ( t < duration/5 ) amplitude = t * 5 / duration ; |
tony1tf | 2:260128ae5746 | 604 | if ( t/multiplier > duration * 0.8 ) amplitude = ( ( duration - t/multiplier ) / duration ) * 8 ; |
tony1tf | 0:8c725fbd8e0e | 605 | |
tony1tf | 1:ba9c803c7596 | 606 | } while ( timer.read() < duration * multiplier ); |
tony1tf | 0:8c725fbd8e0e | 607 | |
tony1tf | 0:8c725fbd8e0e | 608 | } |
tony1tf | 0:8c725fbd8e0e | 609 | |
tony1tf | 0:8c725fbd8e0e | 610 | //============================================================= |
tony1tf | 0:8c725fbd8e0e | 611 | |
tony1tf | 0:8c725fbd8e0e | 612 | |
tony1tf | 0:8c725fbd8e0e | 613 | |
tony1tf | 0:8c725fbd8e0e | 614 |