#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial BTSerial(11, 10); // RX, TX
void setup()
{
// Initialize the LCD display
lcd.init();
// Turn on the backlight
lcd.backlight();
// Set the cursor to the first column of the first row
lcd.setCursor(0, 0);
Serial.begin(9600);
// Start the serial communication
BTSerial.begin(9600);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Send a Message!”);
while (!BTSerial.available()) ;
pinMode(2, OUTPUT);// Red led to notify the listner
}
void loop()
{
// Check if there is data available on the serial port
if (BTSerial.available()) {
// Read the data and store it in a string
digitalWrite(2, HIGH);
delay(200);
digitalWrite(2, LOW);
delay(50);
digitalWrite(2, HIGH);
delay(300);
digitalWrite(2, LOW);
delay(50);
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
delay(50);
Serial.println(“available”);
String input = BTSerial.readStringUntil(‘\n’);
input.remove(input.length() – 1); // remove \n
Serial.println(input);
// Clear the LCD display
lcd.clear();
// Determine if the input string fits on the first line
if (input.length() <= 16) {
// Set the cursor to the first column of the first row
lcd.setCursor(0, 0);
// Print the input string on the LCD display
lcd.print(input);
} else {
// Print as much of the input string as will fit on the first line
lcd.setCursor(0, 0);
lcd.print(input.substring(0, 16));
// Print the remainder of the input string on the second line
lcd.setCursor(0, 1);
lcd.print(input.substring(16));
}
}
}
مشروع جيد هل يمكن استخدامه من أجل عمل مشروع فصلي