case 02 Morse Code
Use basic kit to complete morse code.
1 x basic kit
Morse Code is a method of transmitting text information as a series of on-off tones, lights, or clicks that can be directly understood by a skilled listener or observer without special equipment. It is named for Samuel F. B. Morse, an inventor of the telegraph. The International Morse Code encodes the ISO basic Latin alphabet, some extra Latin letters, the Arabic numerals and a small set of punctuation and procedural signals (prosigns) as standardized sequences of short and long signals called "dots" and "dashes", or "dits" and "dahs", as in amateur radio practice.
Table of Morse Code
Connect the crash sensor to P1 port on basic:bit. See picture below.
ADKeypad analog read the return value of I/O port. Here's the values:
- Button A <10
- Button B: 10-80
- Button C: 80-130
- Button D: 130-160
- Button E: 160-600
When start, display an image, set variable
item to the data that ready to be sent, and set variable
flag to the length of string.
Set a radio group to 50.
Judge if the variable
flag(string length) is 4. (in this case, we use English letters in Morse Code only, so the maximum length is 4.) If it is 4, then show string "A" to the user.
Analog read the value of P1 port. Judge which button is pressed. If the return value is among 80-130, then it is button C that was pressed.
When button C is pressed, increase the string length variable(
flag) by 1, and play a tone for 1/8 beat, then display a pixel point on micro:bit screen, which stands for a dot in morse code. In the final, delay time to de-shock, and write character "0" to the end of the string.
The event of button D is similar to button C, but it will display a dash (in morse code) on micro:bit screen, and write character "1" to the end of the string.
When button A is pressed, display the string and then send it. At the same time, set variable
flag to 0 and initialize the program.
The link of the whole program: https://makecode.microbit.org/_3JrVPeeDVY2r
You can also check the program from the page below.
Press down button C, micro:bit screen will display a dot; press down button D, then it will display a dash. When the total press amount for button C or D is 4, then micro:bit will display the character A. At this time, we need to press button A to restart the program.
Why we need to delay time and debounce ?