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 Morse character to Java as you blink the LED for that character (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 the Morse code 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 letter by using array-like notation. For example, this would print each letter 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 that 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 chose 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
    • a space ensures the LED is off for a total of 7 units
    • between the dots and dashes of a single symbol’s code, turn the LED off for 1 unit. 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 symbols the LED should be off for 3 units. For example, if coding two letters, like AB you would have to blink the code for A, which is ._, and the code for B, which is -.... The LED should be off for three units of time between the final symbol of A and the start of B to indicate the end of a letter.
    • 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:       1234567890123456789012345678901234567890123456789012345678901234567890123
Message:    O----------   H----       H----   E   L--------   L--------   O----------
Signal:     HHHLHHHLHHHLLLHLHLHLLLLLLLHLHLHLLLHLLLHLHHHLHLHLLLHLHHHLHLHLLLHHHLHHHLHHH
             ^     ^      ^       ^             ^
            dash   |     dot      |             |
             symbol space     word space  letter space
Character Complete Morse Code Each Symbol LED On Time LED Off Time
O --- - (1st -) 3 1
  - (2nd -) 3 1
  - (3rd -) 3 1
(between letter)       2 (total of 3 including above)
H .... . (1st) 1 1
  . (2nd) 1 1
  . (3rd) 1 1
(between letter)       2 (total of 3 including above)
` ` (space)       4 (total of 7 including above)
H ... . (1st) 1 1
  . (2nd) 1 1
  . (3rd) 1 1
(between letter)       2 (total of 3 including above)
E . . 1 1
(between letter)       2 (total of 3 including above)
L .-.. . 1 1
  - 3 1
  . 1 1
  . 1 1
(between letter)       2 (total of 3 including above)
L .-.. . 1 1
  - 3 1
  . 1 1
  . 1 1
(between letter)       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:

    - `MorseCoder/`
            - `MorseCoder.ino`
            - `MorseCodes.cpp`
            - `MorseCodes.h`
    - `communication/`
            - `SerialComm.java`
  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 demo your assignment to a TA.
    • Your sketch is able to read input from Java
    • Your sketch correctly iterates over the string returned by moreseEncode()
    • Your sketh 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 dots/dashes
    • Your LED is off for three units of time between symbols
    • 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 2024-10-03 20:24:43 +0000.
Page written by Julia Vogl, Bill Siever, Jeremy Goldstein, Evan Simkowitz, and James Orr.