Intro to Computer Engineering

Assignment 5 - More Morse Mayhem: - - - - - .-. … .

Click here to access the Canvas page with the repository for this assignment.

========

The idea

In this module you will incorporate non-blocking delta timing into the Morse code assignment from Module 4. You will add an LED to your Arduino which will turn on for short (and slightly longer) amounts of time corresponding to dots and dashes in the Morse encoding of messages sent from Java.

By the end of this assignment you should have a better understanding of how delta timing works and how it can be used. In addition, you will practice: iterating through arrays, working with ASCII characters, and considering the logic required to properly implement non-blocking (i.e., delta) timing.

========

The Arduino Assignment

  1. Begin by importing your Java code and MorseCoder.ino from Assignment 4 into their appropriate spots in Assignment 5. All functionality from Assignment 4 should still be in this assignment. Java will still send a user-input message to Arduino to be encoded. The Arduino will then still encode the message and send it back to Java. However, rather than sending it back all at once as in Assignment 4, you should send each dot, dash, and space to Java as you blink the LED for it (see below).

  2. Update your C code to have the Arduino blink an LED for the given Morse code (and send each dot or dash back to Java as you do). You will have to process each character of that string separately. For example, the morseEncode() function will return a String. You will have to loop through the returned string, retrieve each character, and use the character to turn on an LED for the appropriate amount of time. You can access an individual character by using array-like notation. For example, this would print each character in a string one-at-a-time:

String words = "Hello World!";
for(int i=0;i<words.length();i++) {
    Serial.print(words[i]);
}

However, you may not use a for or while loop in this assignment to accomplish timing! If we were to incorporate delta timing behavior into the above for loop, the code would be considered blocking because program control would never leave the loop while you were waiting for it to be time to blink your light on or off. Instead, you must find a way to use the repetitive nature of the Arduino’s loop() function to accomplish the same thing. Hint: you can use a global variable to iterate over an array at appropriate times.

  1. The timing of Morse code should be as follows:
    • you choose the duration of 1 unit; 500 ms is a good choice
    • a dot, ., turns the LED on for 1 unit
    • a dash, -, turns the LED on for 3 units
    • the dots and dashes that make up one character’s code are its elements. Between the elements of a single character, turn the LED off for 1 unit (an element gap). For example, the code for A is .-. The LED needs to be off for 1 unit between when it is on for the . and then on again for the -.
    • between two characters the LED should be off for 3 units total (a character gap). For example, to send AB you would blink the code for A, which is .-, and then the code for B, which is -.... The LED should be off for three units between the final element of A and the first element of B to mark the end of a character.
    • a space in the message means the LED is off for 7 units total (a word gap)
    • when not displaying a dot or a dash the LED should be turned off.

Here are two visualizations showing the full encoding of OH HELLO:


Time:       12345678901234567890123456789012345678901234567890123456789012345678901234567
Message:    O----------   H------       H------   E   L--------   L--------   O----------
Signal:     HHHLHHHLHHHLLLHLHLHLHLLLLLLLHLHLHLHLLLHLLLHLHHHLHLHLLLHLHHHLHLHLLLHHHLHHHLHHH
             ^     ^      ^         ^           ^
             dash  |      dot       |           |
                   element gap      word gap    character gap
Character Complete Morse Code Each Element LED On Time LED Off Time
O --- - (1st -) 3 1
”   - (2nd -) 3 1
”   - (3rd -) 3 1
(between characters)       2 (total of 3 including above)
H .... . (1st) 1 1
”   . (2nd) 1 1
”   . (3rd) 1 1
”   . (4th) 1 1
(between characters)       2 (total of 3 including above)
` ` (space)       4 (total of 7 including above)
H .... . (1st) 1 1
”   . (2nd) 1 1
”   . (3rd) 1 1
”   . (4th) 1 1
(between characters)       2 (total of 3 including above)
E . . 1 1
(between characters)       2 (total of 3 including above)
L .-.. . 1 1
”   - 3 1
”   . 1 1
”   . 1 1
(between characters)       2 (total of 3 including above)
L .-.. . 1 1
”   - 3 1
”   . 1 1
”   . 1 1
(between characters)       2 (total of 3 including above)
O --- - (1st -) 3 1
”   - (2nd -) 3 1
”   - (3rd -) 3 1

Although you may initially use delay() timing to get going with the assignment, when you’re done you should only be using delta timing (i.e., NO delay() or blocking loops allowed).

========

Demo

The following video shows a brief demo of the expected timing:

========

The check-in

Verify that you have completed the following files:

  1. Commit all your code. Do not ask to be checked out by a TA until after you have made certain that your work is committed. Failing to do this may result in you losing points on your assignment.

  2. Follow the checklist below to see if you have everything done before demoing your assignment to a TA.
    • Your sketch is able to read input from Java
    • Your sketch correctly iterates over the string returned by morseEncode()
    • Your sketch sends each '.' '-' and ' ' to your Java program over the Serial port as your code does the appropriate blinking.
    • Your LED lights up for one unit of time for a dot
    • Your LED lights up for three units of time for a dash
    • Your LED is off for one unit of time between the elements of a character
    • Your LED is off for three units of time between characters
    • Your LED is off for seven units of time between words
    • Your sketch uses non-blocking delta timing (no loops!)
    • Your Java program reads lines of characters and sends them through the serial port
    • Your Java program uses debug to display the outgoing and incoming data as the LED is blinking.
    • All of your files are committed
  3. Check out with a TA.

Generated at 2026-10-09 20:51:54 +0000.
Page written by Julia Vogl, Bill Siever, Jeremy Goldstein, Evan Simkowitz, and James Orr.