Hi im working on a project about a morse code translator.
Process
- You type on the serial monitor what you want to translate
- The LCD will display it
Now the problem is...if I type in a sentence that is too long.... I will send a picture so you guys can understand better. The picture shows "my name is edgar" displayed in the lcd. I typed in the serial monitor "my name is edgar steven olazo"
So may question is..how can I display it in the serial monitor like this:
my name is edgar
steven olazo
here is the code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, NEGATIVE);
#define I2C_ADDR 0x27 // Define the address of the serial communication display
#define LED_OFF 0
#define LED_ON 1
#define debug true
int ledPin = 13; //The pin, your LED is connected to.
int speakerPin = 9; //The pin, your buzzer or speaker is connected to.
int pitch1 = 140;
int pitch2 = 140;
int dot = 50;
int dash = 3 * dot;
String morseATable[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", // A-G
"....", "..", ".---", "_._", ".-..", "--", "-.", // H-N
"---", ".--.", "--.-", ".-.", "...", "-", "..-", // O-U
"...-", ".--", "-..-", "-.--", "--.." // V-Z
};
String morseNTable[] = { "-----", ".----", "..---", "...--", "....-", // 0-4
".....", "-....", "--...", "---..", "----." // 5-9
};
void setup()
{
lcd.begin(16, 2); //Initialize the display
lcd.setBacklight(LED_OFF);
lcd.cursor();
pinMode(ledPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
if (debug)
Serial.println("\nSTART");
}
void loop ()
{
if(true){
convert2Morse(Serial.readString());
}
}
void convert2Morse(String message)
{
for (int pos = 0; pos < message.length(); pos++)
{
if (debug)
{
Serial.print(message.charAt(pos));
Serial.print(" ");
lcd.print(message.charAt(pos));
}
if ((message.charAt(pos) >= 97) && (message.charAt(pos) <= 122))
morseLED(morseATable[message.charAt(pos)-97]);
if ((message.charAt(pos) >= 48) && (message.charAt(pos) <= 57))
morseLED(morseNTable[message[pos]-48]);
if (message.charAt(pos) == 32)
morseLED(" ");
if (debug)
Serial.println();
}
delay(5000);
lcd.clear();
}
void morseLED(String sequence)
{
for (int pos = 0; pos < sequence.length(); pos++)
flashLED(sequence.charAt(pos));
delay(2 * dot);
}
void flashLED(char dotOrDash)
{
if (debug)
Serial.print(dotOrDash);
if (dotOrDash == 46)
{
digitalWrite(ledPin, HIGH);
tone (speakerPin, pitch1);
delay(dot);
digitalWrite(ledPin, LOW);
noTone(speakerPin);
delay(dot);
}
else
if (dotOrDash == 45)
{
digitalWrite(ledPin, HIGH);
tone (speakerPin, pitch2);
delay(dash);
digitalWrite(ledPin, LOW);
noTone(speakerPin);
delay(dot);
}
else
if (dotOrDash == 32)
delay(dot);
}
