#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the LCD library with appropriate pins
const int button1Pin = 6; // Pin for pushbutton 1
const int button2Pin = 7; // Pin for pushbutton 2
String receivedContent = ""; // Store the received file content
bool modifyText = false; // Flag to indicate text modification
bool fileReceived = false; // Flag to indicate file reception
bool fileSent = false; // Flag to indicate file sent
void setup() {
Serial.begin(9600); // Initialize serial communication
lcd.begin(16, 2); // Initialize the LCD
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
while (!Serial) {
; // Wait for serial port to connect
}
lcd.print("Waiting for file...");
}
void loop() {
if (Serial.available()) {
// Receive the file
while (Serial.available()) {
char c = Serial.read();
receivedContent += c;
}
// Display message when file is received
lcd.clear();
lcd.print("File received!");
fileReceived = true;
}
if (digitalRead(button1Pin) == LOW) {
if (fileReceived) {
modifyText = true;
lcd.clear();
lcd.print("Editing text...");
while (digitalRead(button1Pin) == LOW) {
// Wait for button release
}
} else {
lcd.clear();
lcd.print("File not received.");
delay(2000);
lcd.clear();
lcd.print("Waiting for file...");
}
}
if (modifyText) {
// Modify the content
String studentName = "John Doe"; // Replace with actual student name
String studentNumber = "123456"; // Replace with actual student number
String goal = "to excel in Digital Systems B2"; // Replace with actual goal
receivedContent.replace("#Student name and surname", studentName);
receivedContent.replace("#student number", studentNumber);
receivedContent.replace("#goal", goal);
lcd.clear();
lcd.print("Change made!");
modifyText = false;
}
if (digitalRead(button2Pin) == LOW) {
if (modifyText) {
lcd.clear();
lcd.print("File not modified.");
delay(2000);
lcd.clear();
lcd.print("Editing text...");
} else {
// Send the modified file back to the PC
Serial.write(receivedContent.c_str());
lcd.clear();
lcd.print("File sent!");
fileSent = true;
while (digitalRead(button2Pin) == LOW) {
// Wait for button release
}
}
}
if (fileSent) {
lcd.clear();
lcd.print("File sent to PC.");
fileSent = false;
}
}