Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
1 result

software-development-project

  • Clone with SSH
  • Clone with HTTPS
  • Morse Code implementation using two Microbits

    Implemented using C++

    File breakdown

    Main.cpp

    This file is where the entirety of the code resides. You can find a mix of for and while loops, if and if else statements, uBit functions, and our own functions. To access, go to "source/main.cpp/".

    How to compile

    To compile, copy the code into your cpp file and run "yt build". This will build as long as you have all of the neccessary files to accompany the build. After this, go to "build/bbc-microbit-classic-gcc/source/iot-example-combined.hex" and copy it onto your Microbit. This will cause the Microbit to restart, running the hex code.

    The implementation

    After the two Microbits have restarted and are running the code, you will see a blank screen on both of them. Its important to note that one Microbit will be the sender (Master) and the other will be listening (Slave), to change this, edit the code in main.cpp which turns listener on/off. This the the listen variable within the start of main. We will use Button A to create dots and dashes, and then use the same button to send our string to the other Microbit via IO pins. NOTE: We use Button A for every job, this emulates a real life scenario.

    The protocol

    This program creates a protocol between two Microbit's connected by a wire on pin 0 and GND to send voltages to each other. The voltages represent 0s (.) and 1s (-). These binary numbers are added to a string then converted into their symbols and then checked against an alphabet array.

    Controls

    To display a dot, simply press Button A for anything less than half a second. For a dash, hold Button A for more than half a second, up to 2 seconds. To send the string, hold the button for more than 2 seconds.

    If you would like to restart the game, simply press the circular black button on the back of the Microbit, which is on the right of the micro USB input.

    The outcome

    After you are happy with the string that you have written on the master Microbit, you can send it. After this, the pattern of dots and dashes that you have input will be compared to the stored sequences within the program, and a matching character from a-z & 0-9 will be displayed on both microbit screens.

    How does the program work?

    On a base level, the program works by waiting for a button input, and then when it is given, timing the length of that button press, and then depending on the length of time adding either a dot, dash, or finishing the pattern. To gain a detailed understanding of how the program works, simply go to the main.cpp file and read through the descriptive comments which are designed to explain what each variable and function does.