#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const int buzzerPin = 13;
const int buttonPin = 2;
const int secondButtonPin = 4;
const int interpretButton =3;
int lungimeMesaj=0;
char* mesaj[5]= {' ',' ',' ',' ',' '};
const char* morse[36] = {".- ", "-... ", "-.-. ", "-.. ", ". ", "...- ",
"--. ", ".... ", ".. ", ".--- ", "-.- ", ".-.. ",
"-- ", "-. ", "--- ", ".--. ", "--.- ", ".-. ",
"... ", "- ", "..- ", "...- ", ".-- ", "-..- ",
"-.-- ", "--.. ", ".----", "..---", "...--", "....-",
".....", "-....", "--...", "---..", "----.", "-----"
};
const char *litere = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
byte customChar[8] =
{
B00000,
B00000,
B01110,
B01110,
B01110,
B01110,
B00000,
B00000
};
void setup()
{
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(secondButtonPin, INPUT_PULLUP);
pinMode(interpretButton, INPUT_PULLUP);
lcd.createChar(0, customChar);
lcd.init();
lcd.backlight();
}
int ok= 0;
void loop()
{
if (digitalRead(buttonPin) == LOW)
{
delay(200);
tone(buzzerPin, 1000);
Serial.print('-');
mesaj[lungimeMesaj]='-';
lungimeMesaj++;
delay(500);
noTone(buzzerPin);
delay(200);
}
if (digitalRead(secondButtonPin) == LOW)
{
delay(200);
tone(buzzerPin, 200);
Serial.print('.');
mesaj[lungimeMesaj]='.';
lungimeMesaj++;
delay(500);
noTone(buzzerPin);
delay(200);
}
if (digitalRead(interpretButton) == LOW)
{
delay(400);
Serial.print("=");
for(int i=0; i<36; i++)
{
ok=0;
for(int j=0; j<5; j++)
{
if(mesaj[j]==morse[i][j])
{
ok++;
}
}
if(ok==5)
{
lcd.setCursor(7, 1);
lcd.print(litere[i]);
}
}
lcd.setCursor(6, 0);
for(int i=0; i<5; i++)
{
if(mesaj[i]=='.')
{
lcd.print(".");
}
if(mesaj[i]=='-')
{
lcd.print("-");
}
mesaj[i]=' ';
lungimeMesaj=0;
}
delay(200);
}
}