PHYSCI 70: Introduction to Digital Fabrication

Marie Konopacki

Final Project Proposal

About Me

Week 4

For this week, we were assigned to make a “microcontroller do something”. I spent some time trying to think about what I would make it do. I wanted to lean more into the coding side of the project, considering I was really interested in the prospect of written code achieving real life commands. Although I’ve coded before, it was always front-end web development, so everything my code achieved was purely on a screen. Eventually, I decided to make a morse code translator.

Essentially, it takes in a user-inputted string, and then the microcontroller, using its built-in LED, would flash, in morse code, the original input. For the code, I created functions that turned the LED on for both short and long increments. I then made a switch case for each letter of the alphabet and used a morse-code chart I found online to properly assign functions to each one.

Overall, I'm pretty satisfied with the finished project. To the left, I've attached a demo of me inputting the string "marie". Attached below is the code I wrote to achieve this project.

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);

}

String input = "";

void loop() {
  if (Serial.available() > 0) {
    input = Serial.readStringUntil('\n');

    Serial.print(input);

    for(int i = 0; i<input.length(); i++) {
        char letter = input[i];

        switch (letter) {
          case 'a':
            Short();
            Long();
            break;
          case 'b':
            Long();
            Short();
            Short();
            Short();
            break;
           case 'c':
            Long();
            Short();
            Long();
            Short();
            break;
           case 'd':
            Long();
            Short();
            Short();
            break;
           case 'e':
            Short();
            break;
           case 'f':
            Short();
            Short();
            Long();
            Short();
            break;
           case 'g':
            Long();
            Long();
            Short();
            break;
           case 'h':
            Short();
            Short();
            Short();
            Short();
            break;
           case 'i':
            Short();
            Short();
            break;
           case 'j':
            Short();
            Long();
            Long();
            Long();
            break;
           case 'k':
            Long();
            Short();
            Long();
            break;
           case 'l':
            Short();
            Long();
            Short();
            Short();
            break;
           case 'm':
            Long();
            Long();
            break;
           case 'n':
            Long();
            Short();
            break;
           case 'o':
            Long();
            Long();
            Long();
            break;
           case 'p':
            Short();
            Long();
            Long();
            Short();
            break;
           case 'q':
            Long();
            Long();
            Short();
            Long();
            break;
           case 'r':
            Short();
            Long();
            Short();
            break;
           case 's':
            Short();
            Short();
            Short();
            break;
           case 't':
            Long();
            break;
           case 'u':
            Short();
            Short();
            Long();
            break;
           case 'v':
            Short();
            Short();
            Short();
            Long();
            break;
           case 'w':
            Short();
            Long();
            Long();
            break;
           case 'x':
            Long();
            Short();
            Short();
            Long();
            break;
           case 'y':
            Long();
            Short();
            Long();
            Long();
            break;
           case 'z':
            Long();
            Long();
            Short();
            Short();
            break;
        }
       delay(1500);
    }
  }
}

void Long() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1200);
  digitalWrite(LED_BUILTIN, LOW);
  delay(200);
}

void Short() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(300);
  digitalWrite(LED_BUILTIN, LOW);
  delay(200);
}