Circuit Playground Express Wearable Morse Transmitter

by Mr_whale in Circuits > Arduino

346 Views, 3 Favorites, 0 Comments

Circuit Playground Express Wearable Morse Transmitter

morse-code-overview.png

The Circuit Playground Express is a small but powerful computer that fits in the palm of your hand. However, it doesn't have very good long distance communication, or much human-readable information at all. To combat this issue, I chose to go back and pick a solution from the past: Morse code! Morse code works on a basis of turning short and long beeps and silences into letters. The chart above shows how. A short beep is a dot and a long beep is a dash. Between letters there are short silences, and between words there are longer silences. So, if tThis glove uses different light colors as well as different lengths to make it easy to decipher, even if you don't have that much experience with morse code.

Supplies

Circuit Playground Express (Abbreviated to CPX)

Battery pack (with batteries)

Computer (for Adafruit coding)

Wearable eleFelt strip or glove

Getting User Input

Screenshot 2021-06-04 at 13.42.31.png
Screenshot 2021-06-04 at 13.47.01.png
Screenshot 2021-06-08 at 10.29.54.png

In order to be a functional interactive experience, we need a way to get user input. We will use the two built-in buttons on the CPX, but you could modify the code to work with the capacitive touch buttons if you wanted to. The first thing to do is set up the "on start" block. This will contain the user input array, which I called list, and is how the computer will store user input. After that, the next step is to add the code for interpreting the clicks of the A and B buttons. The A button will be for dots and dashes, and the B button will be for spaces and letter separations. If you click both at the same time, it will clear the list, removing whatever dots and dashes you have put in. When the A or B button is pressed, the code will wait 0.3 seconds before checking if it is still pressed. If it is, it will be considered a dash, or a space between words. If it isn't, it will be a dot or space between letters. The space between dots or dashes will be added automatically at a later step. The append line is how we will store the information. This will be read in the next step so that it will output the morse at the correct speed, with the correct combination of dots and dashes.

If you don't want the explanation, this is the code in java, for both this step and the next.

input.buttonA.onEvent(ButtonEvent.Down, function () {
    control.waitMicros(300000)
    if (!(input.buttonA.isPressed())) {
        list.push(1)
        light.showRing(
        `blue blue blue blue blue blue blue blue blue blue`
        )
        control.waitMicros(50000)
        light.showRing(
        `black black black black black black black black black black`
        )
    } else {
        list.push(2)
        light.showRing(
        `red red red red red red red red red red`
        )
        control.waitMicros(150000)
        light.showRing(
        `black black black black black black black black black black`
        )
    }
})
input.buttonsAB.onEvent(ButtonEvent.LongClick, function () {
    list = []
    light.showRing(
    `white white white white white white white white white white`
    )
})
input.buttonB.onEvent(ButtonEvent.Down, function () {
    control.waitMicros(300000)
    if (!(input.buttonB.isPressed())) {
        list.push(0)
        light.showRing(
        `white white white white white white white white white white`
        )
        control.waitMicros(50000)
        light.showRing(
        `black black black black black black black black black black`
        )
    } else {
        list.push(-1)
        light.showRing(
        `white white white white white white white white white white`
        )
        control.waitMicros(150000)
        light.showRing(
        `black black black black black black black black black black`
        )
    }
})
function dispMorse () {
    light.setBrightness(200)
    for (let index = 0; index <= list.length; index++) {
        let needHelp = 0
        network.infraredSendNumber(needHelp)
        if (list[index] == 1) {
            light.showRing(
            `blue blue blue blue blue blue blue blue blue blue`
            )
            control.waitMicros(100000)
        } else if (list[index] == 2) {
            light.showRing(
            "red red red red red red red red red red"
            )
            control.waitMicros(300000)
        } else if (list[index] == 0) {
            light.showRing(
            `black black black black black black black black black black`
            )
            control.waitMicros(600000)
        } else {
            light.showRing(
            `black black black black black black black black black black`
            )
            control.waitMicros(200000)
        }
        light.showRing(
        `black black black black black black black black black black`
        )
        control.waitMicros(100000)
    }
}


network.onInfraredReceivedNumber(function (needHelp) {
    light.setBrightness(60)
    light.showRing(
    `yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow`
    )
    control.waitMicros(100000)
    light.showRing(
    `black black black black black black black black black black`
    )
})
let list: number[] = []
list = []
light.showRing(
`black black black black black black black black black black`
)
forever(function () {
    if (input.switchRight()) {
        dispMorse()
    }
})

Outputting to the CPX

Screenshot 2021-06-08 at 10.28.41.png
Screenshot 2021-06-08 at 10.29.45.png
Screenshot 2021-06-08 at 10.29.30.png

To output, the first step is to set up how you will change modes. This is done in the forever loop, with a simple if statement detecting if the switch is right or not. If it is, it will run the dispMorse function. In this function, it will read the list we made in the last step. It will also display an IR message to anyone else running the code, making it clearer that you need help. It will go through the list, and depending on what number it is, it will display a dot, dash, letter space, or word space. It will iterate again if the switch is still right once it is finished. This is all the code, and the timings have been optimized to be proportional to the original morse guidelines, while still being slow enough that beginners can understand. You can tweak these values to make it slower or faster depending on your level of morse expertise.

Create the Mounting Mechanism

IMG_1669.png
IMG_1670.png
IMG_1671.png

The final step is to attach the coded CPX to your wearable element, whether it is a wristband, glove, or some other fabric. I sewed it to a black felt strip, to which I attached some velcro for an easily adjustable wristband. After that, you can tuck the battery pack into one of the folds of the fabric, or put it somewhere else if you have an idea.