Morse Code Encoder

Materials Needed: 

  • Circuit Playground 
  • Crikit (optional) 
  • 3 neopixel strips with at least 5 neopixels 
  • Thin wire 
  • Alligator clips with female end 
  • Soldering Iron 
  • Hot glue gun
  • Solder 
  • Popicle sticks 
  • Glass Jars 
  • White paint 
  • Paint sponge

Instructions

Step 1 : Paint glass jars with a thin layer of white paint using a wet paint sponge, also paint popsicle sticks.

Step 2: Cut 9 strips of wire

Step 3: Strip the ends of each wire and tin with solder

Step 4: Add solder to the Ground, Volts, and input tabs of each neopixel strip

Step 5: Solder wires to one end of each neopixel strip. Make sure arrows are going away from you

Step 6: Connect alligator clips to circuit playground on Ground, Vout, and A1 pins

**Note: Crickit can be used instead with wire connected on neopixel port

Step 8: Solder all strands together. Test again if necessary

Step 9: Hot glue solder joints on all neopixel strips

Step 10: Attach neopixel strips to painted popsicle sticks. This will serve as a sturdy surface so that the light doesn’t move in the jar

Step 11: Place each neopixel strip within the jar. Hot glue wires down as necessary

 

############# Arduino Code ##############

/*
* Will take in a serial message from processing
* and convert it to the morse code equivalent
* Will then display the message by having lights
* blink in the morse code pattern
*/

#include <Adafruit_NeoPixel.h>
#include <Adafruit_CircuitPlayground.h>

String val;
char alphabet[27] = {‘A’,’B’, ‘C’, ‘D’,’E’,’F’,’G’, ‘H’,’I’,’J’, ‘K’, ‘L’,’M’,’N’,’O’,’P’,
‘Q’, ‘R’, ‘S’, ‘T’,’U’,’V’, ‘W’, ‘X’, ‘Y’, ‘Z’};
char morse[26][5] = {“.-“,”-…”,”-.-.”,”-..”, “.”, “..-.”,”–.”,”….”,”..”,”.—“,”-.-“,”.-..”, “–“,”-.”,”—“,
“.–.”, “–.-“, “.-.”, “…”, “-“, “..-“, “…-“, “.–“, “-..-“, “-.–“,”–..”};

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN A1

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 15

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
Serial.begin(115200);

strip.begin();
strip.show();
strip.setBrightness(50);

}

void loop() {
if(Serial.available()) {
val = Serial.readString();
}

//val = “sos1”;
if(val.indexOf(“1”) >= 0 ) {

String cleanWord = cleanWordUp(val);
String mWord = convertToMorse(cleanWord);
Serial.println(“Morse Corversion: “+mWord); //debugging
convertToLights(mWord);

}
else if(val.indexOf(“off”) >= 0){
strip.clear();
strip.show();
Serial.println(“In Else if: ” + val);
}
else{
standbyMode();
Serial.println(“In Else: ” + val);
}

}

//Function to split up the word and capitalize in order
//to convert to morse code
String cleanWordUp(String w) {
String cleanedWord;
int l = w.length();

w.remove(l-1,1);
cleanedWord = w;
cleanedWord.toUpperCase();

return cleanedWord;
}

//Function to convert word to the morse equivalent
String convertToMorse(String str) {
String outputWord = “”;

for(int i = 0; i < str.length(); i++){
for(int j = 0; j < 27; j++){
if(str[i] == alphabet[j] ){
outputWord = outputWord + morse[j];
outputWord = outputWord + ” “;
Serial.println(outputWord); //For debugging purposes only
}
}
}
return outputWord;

}//end function

//Function to get lights to blink in the correct pattern
//Will eventually add in the other pixels and turn them on accordinly
void convertToLights(String morse) {
int l = morse.length();
//Serial.println(l); for debugging only

for(int i = 0; i < morse.length()+4; i++) {
if(morse[i] == ‘.’){
delay(200);
Serial.println(“IN IF”);
//First set of neopixel lights
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 255, 0, 0);

//Second set of neopixel lights
strip.setPixelColor(5, 0, 255, 0);
strip.setPixelColor(6, 0, 255, 0);

//Third set of lights
strip.setPixelColor(10, 0, 0, 255);
strip.setPixelColor(11, 0, 0, 255);

strip.show();
delay(300);
strip.clear();
strip.show();

}
else if(morse[i] == ‘-‘) {
//first set of neopixel lights
strip.setPixelColor(2, 255, 0, 0);
strip.setPixelColor(3, 255, 0, 0);
strip.setPixelColor(4, 255, 0, 0);

//Second set of neopixel lights
strip.setPixelColor(7, 0, 255, 0);
strip.setPixelColor(8, 0, 255, 0);
strip.setPixelColor(9, 0, 255, 0);

strip.setPixelColor(12, 0, 0, 255);
strip.setPixelColor(13, 0, 0, 255);
strip.setPixelColor(14, 0, 0, 255);

strip.show();

Serial.println(“IN ELSE IF”);
delay(400);
strip.clear();
strip.show();
delay(300);
}
else {
strip.clear();
delay(300);
Serial.println(“IN ELSE “);
}
}
}

void standbyMode() {
//First set of neopixel lights
strip.setPixelColor(0, 255, 0, 0);
strip.setPixelColor(1, 255, 0, 0);
strip.setPixelColor(2, 255, 0, 0);
strip.setPixelColor(3, 255, 0, 0);
strip.setPixelColor(4, 255, 0, 0);

//Second set of neopixel lights
strip.setPixelColor(5, 0, 255, 0);
strip.setPixelColor(6, 0, 255, 0);
strip.setPixelColor(7, 0, 255, 0);
strip.setPixelColor(8, 0, 255, 0);
strip.setPixelColor(9, 0, 255, 0);

//Third set of lights
strip.setPixelColor(10, 0, 0, 255);
strip.setPixelColor(11, 0, 0, 255);
strip.setPixelColor(12, 0, 0, 255);
strip.setPixelColor(13, 0, 0, 255);
strip.setPixelColor(14, 0, 0, 255);
strip.show();
}

##### Processing Code ###############

/*
* Program will take in user input and send it
* through the serial port to the arduino
* to be displayed as lights
* * * * * * * * * * * * * * * * * * * * * * */

import processing.serial.*;

Serial myPort; //Initializing a variablf for serial communication

PFont f; //Declare the PFont variable

String userText = “”;
boolean userDone = false;
String[] textFile;
String morseWord = “”;
String word;
int readVal;

void setup() {
f = createFont(“Zapfino”, 30, true);
size(500,500);

//Set up the com port and the serial rate
printArray(Serial.list());
myPort = new Serial(this, “/dev/cu.usbmodem1421”, 115200);
//myPort.bufferUntil(lf);
}

void draw() {
background(255);
textFont(f);
fill(0);

if(userDone) {
text(userText, 220, 250);
String morse = insertCharacter(userText);
myPort.write(“hello1”);
//while ( myPort.available() > 0) { // If data is available,
////readVal = myPort.read(); // read it and store it in
//myPort.write(morse);
//}
println(“MousePressed word: ” + morse);
}

if(mousePressed) {
background(255);
userText = “”;
userDone = false;
}

}

//Function that will create word as the user types
//Once user presses enter the DONE flag is set
void keyPressed() {
if(key == BACKSPACE) {
if(userText.length() > 0) {
userText = userText.substring(0, userText.length()-1);
println(“BACKSPACE”);
myPort.write(‘0’);
}
}
else if(key == RETURN || key == ENTER) {
userDone = true;
}
else {
userText+=key;
println(userText);
//myPort.write(‘0’);
}

}

//Function to insert a delimeter after the word
//So that arduino knows when to turn on the led strip
String insertCharacter(String w){
String newWord;
newWord = w.trim() + “1”;
// println(newWord); //Check to see that works
return newWord;
}