Hey guys.. Im having some trouble uploading this code.. which I will post down below. Its about a morse code translator. You type in the words in the serial monitor...https://www.instructables.com/id/Learning-Morse/ ..here is the link
#include <Wire.h> //libraries of the LCD with I2C
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // Define the address of the serial communication display
#define LED_OFF 0
#define LED_ON 1
LiquidCrystal_I2C lcd(I2C_ADDR, 2, 1, 0, 4, 5, 6, 7, 3, NEGATIVE);
int ledPin = 8;
char* letters[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", // letters A-I
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", // letters J-R
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." //letters S-Z
};
char* numbers[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....",
"--...", "---..", "----."}; // numbers 0-9
int dotDelay = 200; //Dot time
void setup()
{
lcd.begin(16, 2); //Initialize the display
lcd.setBacklight(LED_OFF);
lcd.cursor();
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
char ch;
if (Serial.available()) // is there anything to be read from USB?
{
ch = Serial.read(); // read a single letter
if (ch >= 'a' && ch <= 'z')
{
flashSequence(letters[ch - 'a']);
lcd.write(ch);
delay(1500);
}
else if (ch >= 'A' && ch <= 'Z')
{
flashSequence(letters[ch - 'A']);
lcd.write(ch);
delay(1500);
}
else if (ch >= '0' && ch <= '9')
{
flashSequence(numbers[ch - '0']);
lcd.write(ch);
delay(1500);
}
else if (ch == ' ')
{
delay(dotDelay * 4); // gap between words
lcd.write(ch);
delay(1500);
}
}
}
void flashSequence(char* sequence)
{
int i = 0;
while (sequence != NULL)
- {*
_ flashDotOrDash(sequence*);_
_ i++;_
_ }_
_ delay(dotDelay * 3); // gap between letters_
_ }_
void flashDotOrDash(char dotOrDash)
_ {_
_ digitalWrite(ledPin, HIGH);_
_ if (dotOrDash == '.')_
_ {_
_ delay(dotDelay);_
_ }_
_ else // must be a -_
_ {_
_ delay(dotDelay * 3);_
_ }_
_ digitalWrite(ledPin, LOW);_
_ delay(dotDelay); // gap between flashes*_
* }*