//by Nissanka Md Weerasinghe @COTM
#include <LiquidCrystal_I2C.h> //++++++++++++++++++++++++
#include <SoftwareSerial.h>
#define I2C_ADDR1 0x27 //++++++++++++++++++++++++
#define I2C_ADDR2 0x29 //++++++++++++++++++++++++
#define LCD_COLUMNS 20 //++++++++++++++++++++++++
#define LCD_LINES 4 //++++++++++++++++++++++++
#define Encription_Key 20
#define Decription_Key -20
SoftwareSerial link(10,11);
LiquidCrystal_I2C lcd1(I2C_ADDR1, LCD_COLUMNS, LCD_LINES); //++++++++++++++++++++++++
LiquidCrystal_I2C lcd2(I2C_ADDR2, LCD_COLUMNS, LCD_LINES); //++++++++++++++++++++++++
String Incomming_Command;
String Encrypted_Command;
String Decrypted_Command;
void setup() {
Serial.begin(9600);
link.begin(9600);
// Init
lcd1.init(); //++++++++++++++++++++++++
lcd1.backlight(); //++++++++++++++++++++++++
lcd2.init(); //++++++++++++++++++++++++
lcd2.backlight(); //++++++++++++++++++++++++
// Print something
lcd1.setCursor(0, 0); //++++++++++++++++++++++++
lcd1.print("Hello, world!"); //++++++++++++++++++++++++
lcd1.setCursor(0, 1); //++++++++++++++++++++++++
lcd1.print("Wokwi LCD1"); //++++++++++++++++++++++++
lcd2.setCursor(0, 0); //++++++++++++++++++++++++
lcd2.print("Hello, world!"); //++++++++++++++++++++++++
link.println("Hello, world!");
lcd2.setCursor(0, 1); //++++++++++++++++++++++++
lcd2.print("Wokwi LCD2"); //++++++++++++++++++++++++
link.println("Wokwi SoftwareSerial Display");
delay(2000);
lcd1.clear();
lcd2.clear();
lcd1.setCursor(0, 0); //++++++++++++++++++++++++
lcd1.print("Encripted Commnd"); //++++++++++++++++++++++++
lcd2.setCursor(0, 0); //++++++++++++++++++++++++
lcd2.print("Decripted Commnd"); //++++++++++++++++++++++++
Serial.println("Enter the command");
}
void loop() {
bool msg_received = false;
while(Serial.available() > 0)
{
msg_received = true;
Incomming_Command = Serial.readStringUntil('\n');
}
//Data Encrioption ///////
if(msg_received)
{
Serial.println(Incomming_Command);
int Command_size = Incomming_Command.length();
for( int i = 0; i< Command_size; i++)
{
char Command_Char = Incomming_Command.charAt(i);
//Serial.print(Command_Char);
char Encripted_Char = Command_Char + Encription_Key;
Encrypted_Command += Encripted_Char;
}
//Serial.println(Encrypted_Command);
lcd1.setCursor(0, 1); // to clear only the line 1 //++++++++++++++++++++++++
lcd1.print(" "); // to clear only the line 1 //++++++++++++++++++++++++
lcd1.setCursor(0, 1); //++++++++++++++++++++++++
lcd1.print(Encrypted_Command); //++++++++++++++++++++++++
Serial.print("Encripted Command : ");
Serial.println(Encrypted_Command);
//Encrypted_Command = "";
}
//Data Decription //////
int Encrpt_Cmd_size = Encrypted_Command.length();
if(Encrpt_Cmd_size > 0)
{
for( int i = 0; i< Encrpt_Cmd_size; i++)
{
char Command_Char = Encrypted_Command.charAt(i);
//Serial.print(Command_Char);
char Decripted_Char = Command_Char + Decription_Key;
Decrypted_Command += Decripted_Char;
}
Encrypted_Command = ""; // To accept next one
//Serial.println(Encrypted_Command);
lcd2.setCursor(0, 1); // to clear only the line 1 //++++++++++++++++++++++++
lcd2.print(" "); // to clear only the line 1 //++++++++++++++++++++++++
lcd2.setCursor(0, 1); //++++++++++++++++++++++++
lcd2.print(Decrypted_Command); //++++++++++++++++++++++++
Serial.print("Decripted Command : ");
Serial.println(Decrypted_Command);
Decrypted_Command = ""; // To accept next one
}
}