Skip navigation
>

Arduino Morse Code

Description:

\\TO READ THE MORSE CODE USE "MORSE CODE READER" FROM ANDROID APP STORE

 

 

 

\\ARDUINO CODE

 

int lightPin = 11;

int point = 4;

int dash = 2;

 

 

void setup() {

  // put your setup code here, to run once:

  pinMode(lightPin, OUTPUT);

  pinMode(point, OUTPUT);

  pinMode(dash, OUTPUT);

  Serial.begin(9600);

}

 

 

void loop() {

  // put your main code here, to run repeatedly:

  if (Serial.available()) {

    String input = Serial.readString();

    String morse = filterMorse(input);

    showMorse(morse);

  }

}

 

 

String filterMorse(String input) {

  int inputLength = input.length();

  String outputString = "";

 

 

  for (int i = 0; i < inputLength; i++) {

    char c = input[i];

    if (c == '-' || c == '.' || c == ' '  )

    {

      outputString += c;

    }

  }

 

 

  return outputString;

}

 

 

void showMorse(String morse) {

  int morseLength = morse.length();

 

 

  for (int i = 0; i < morseLength; i++) {

    char c = morse[i];

 

 

   if(c == ' ')

   {

    noTone(lightPin);

    delay(240);

   }

 

   

    if (c == '-') {

      //show long dah

      tone(lightPin, 800);

      digitalWrite(point, LOW);

      digitalWrite(dash, HIGH);

      delay(240);

      noTone(lightPin);

      digitalWrite(dash, LOW);

      delay(80);

    }

    else if(c == '.')

    {

    tone(lightPin, 800);

    digitalWrite(dash, LOW);

    digitalWrite(point, HIGH);

    delay(80);

    noTone(lightPin);

    digitalWrite(point,LOW);

    delay(80);

 

    }

  }

}

Comments