Skip to main content

Arduino Project: Morse Code

Today during my conceptual physics class, my teacher introduced the Arduino developing kit, and we started working on it. I had a little experience of coding so it was not hard for me. Therefore, I created this Arduino project that can control the LED on the broad to spell my name using Morse code.

This is the code that I wrote
>>>
int LED = 13;
int dot = 300;
int dash = dot * 3;
int elemPause = dot;
int charPause = dot * 3;
int wordPause = dot * 7;
char fName[] = "allen";
char lName[] = "lin";

void setup() {
  pinMode(LED, OUTPUT);
}
void MorseDot() {
  digitalWrite(LED, HIGH);  
  delay(dot);
}
void MorseDash() {
  digitalWrite(LED, HIGH);  
  delay(dash);
}
void MorseElemPause() {
  digitalWrite(LED, LOW); 
  delay(elemPause);
}
void MorseCharPause() {
  digitalWrite(LED, LOW);
  delay(charPause);
}
void MorseWordPause() {
  digitalWrite(LED, LOW);  
  delay(wordPause);
}
void longPause () {
  digitalWrite(LED, LOW);
}
void pickLetter(char x){
  switch (x) {
      case 'a':
        MorseDot();
        MorseElemPause();
        MorseDash();
        MorseElemPause();
        break;
      case 'e':
        MorseDot();
        MorseElemPause();
        break;
      case 'i':
        MorseDot();
        MorseElemPause();
        MorseDot();
        MorseElemPause();
        break;
      case 'l':
        MorseDot();
        MorseElemPause();
        MorseDash();
        MorseElemPause();
        MorseDot();
        MorseElemPause();
        MorseDot();
        MorseElemPause();
        break;
      case 'n':
        MorseDash();
        MorseElemPause();
        MorseDot();
        MorseElemPause();
        break;
    }
  MorseCharPause();
}
void loop () {
  pickLetter(fName[0]);
  pickLetter(fName[1]);
  pickLetter(fName[2]);
  pickLetter(fName[3]);
  pickLetter(fName[4]);
  MorseWordPause();
  pickLetter(lName[0]);
  pickLetter(lName[1]);
  pickLetter(lName[2]);
  MorseWordPause();
  longPause();
}
>>>

It was a cool experience and I planned to make some videos teaching people how to code Arduino on my Youtube channel about science. Please subscribe my channel if you found the content really interesting(link).

Comments

Popular posts from this blog

7 Musical Modes - I.D.P.L.M.A.L.

There is a way to create 7 kinds of scales easily just by using one chord. This method is called the I.D.P.L.M.A.L. I.D.P.L.M.A.L. refers to: I onian(I)  D orian(ii)   P hrygian(iii)   L ydian(IV)   M ixolydian(V)   A eolian(vi)   L ocrian(vii) The way to memorize it is: I   D on't  P lay  L ike  M iles  A fter  L unch (Miles Davis was an influential musician in the history of the 20th century music) The way to use this method is to start the scale from a different note.  For example, if I have a scale which contains only B flat,  then the one below will be an  F Major scale , which  starts from F(I) : F - G - A - B flat - C - D - E - F  this one will be an F Dorian scale , which starts from G(ii): G - A - B flat - C - D - E - F - G  and this one will be an F Mixolydian scale , which starts from C(V): C - D - E - F - G - A - B flat - C By using the 7 musical modes, you wi...

A Social Marketing Principle - The V.R.I.N. Principle

Today, I saw an ad on Youtube that provides a social marketing course, and it teaches people the key to achieve in the social market. I am just being curious and I went up and signed up for a free training webinar. Unfortunately, I am not affordable for the price of the course. It is $699. But the good news is that I learned a principle of social marketing. It's called the V.R.I.N. principle. I searched it on the web and I found it pretty interesting, it is a way of methods on debugging a company's business strategy and create a sustainable competitive resource for the business. V aluable: If it is useful, ideal, or creative. R are: If it is unique, special, or literally, rare. I mperfectly imitable: If it is easy to be copied by others. N on-substitutable: If it is able to stay on the market as time passes. This method is useful when you just have an idea of starting a business or online platforms. You can now easily check a company with the method and fix the mistakes. ...

Ancient Architectural Style & Sketchup Practice

Today in history class, I learned some different types of architectural style in different ancient time periods -- Ancient Rome, Ancient Greece, and Ancient Egypt. We were assigned to create an ancient style architecture using the Sketchup  program. So, I started up by doing some research with the style of those types of ancient buildings, and this is what I got: Ancient Rome Style: made of stone, arches, pillars, and domes. Ancient Greece Style:   made of columns, door and window openings. Ancient Egypt Style: made of sun-baked mud brick or stone, post and lintel structure. Then I searched "sketchup tutorial", and found that the company has already made a list of video tutorials . They are really helpful, and it helps me a lot to get familiar with the drawing tools. After watching some video tutorials, I first started with a 2D-design draft on a piece of paper using the Ancient Rome style. It looks like this: Then I worked on the design using...