#include <EEPROM.h>
// Define the pins for push buttons
const int PUSH_BUTTON1 = 2;
const int PUSH_BUTTON2 = 3;
const int PUSH_BUTTON3 = 4;
const int PUSH_BUTTON4 = 5;
const int PUSH_BUTTON5 = 6;
// Define the pins for LEDs
const int WHITE_LED1 = 8;
const int BLUE_LED2 = 9;
const int YELLOW_LED3 = 10;
const int SKY_LED4 = 11;
const int GREEN_LED5 = 12;
// Variables to store the status of each button
int status1, status2, status3, status4, status5;
// Define a structure for button press logs
struct ButtonPress {
int serialNumber;
String name;
String date; // Simulated date for simplicity
};
// Button press information
ButtonPress button1 = {1, "Button 1", "2024-09-11"};
ButtonPress button2 = {2, "Button 2", "2024-09-11"};
ButtonPress button3 = {3, "Button 3", "2024-09-11"};
ButtonPress button4 = {4, "Button 4", "2024-09-11"};
ButtonPress button5 = {5, "Button 5", "2024-09-11"};
void setup() {
// Initialize Serial Monitor
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect (necessary on some boards)
}
// Set push button pins as input with internal pull-up resistors
pinMode(PUSH_BUTTON1, INPUT_PULLUP);
pinMode(PUSH_BUTTON2, INPUT_PULLUP);
pinMode(PUSH_BUTTON3, INPUT_PULLUP);
pinMode(PUSH_BUTTON4, INPUT_PULLUP);
pinMode(PUSH_BUTTON5, INPUT_PULLUP);
// Set LED pins as outputs
pinMode(WHITE_LED1, OUTPUT);
pinMode(BLUE_LED2, OUTPUT);
pinMode(YELLOW_LED3, OUTPUT);
pinMode(SKY_LED4, OUTPUT);
pinMode(GREEN_LED5, OUTPUT);
// Optional: Write initial data to EEPROM (if needed)
// EEPROM.write(0, 0);
}
void loop() {
status1 = digitalRead(PUSH_BUTTON1);
status2 = digitalRead(PUSH_BUTTON2);
status3 = digitalRead(PUSH_BUTTON3);
status4 = digitalRead(PUSH_BUTTON4);
status5 = digitalRead(PUSH_BUTTON5);
// Control LED1 with push button 1
if (status1 == HIGH) {
digitalWrite(WHITE_LED1, LOW); // Turn off LED1 if button 1 is not pressed
} else {
digitalWrite(WHITE_LED1, HIGH); // Turn on LED1 if button 1 is pressed
EEPROM.write(0, 1); // Store data 1 in EEPROM address 0
Serial.print("Button ");
Serial.print(button1.serialNumber);
Serial.print(" pressed: Stored ");
Serial.print(1);
Serial.print(" in EEPROM address 0. Name: ");
Serial.print(button1.name);
Serial.print(", Date: ");
Serial.println(button1.date);
}
// Control LED2 with push button 2
if (status2 == HIGH) {
digitalWrite(BLUE_LED2, LOW); // Turn off LED2 if button 2 is not pressed
} else {
digitalWrite(BLUE_LED2, HIGH); // Turn on LED2 if button 2 is pressed
EEPROM.write(1, 2); // Store data 2 in EEPROM address 1
Serial.print("Button ");
Serial.print(button2.serialNumber);
Serial.print(" pressed: Stored ");
Serial.print(2);
Serial.print(" in EEPROM address 1. Name: ");
Serial.print(button2.name);
Serial.print(", Date: ");
Serial.println(button2.date);
}
// Control LED3 with push button 3
if (status3 == HIGH) {
digitalWrite(YELLOW_LED3, LOW); // Turn off LED3 if button 3 is not pressed
} else {
digitalWrite(YELLOW_LED3, HIGH); // Turn on LED3 if button 3 is pressed
EEPROM.write(2, 3); // Store data 3 in EEPROM address 2
Serial.print("Button ");
Serial.print(button3.serialNumber);
Serial.print(" pressed: Stored ");
Serial.print(3);
Serial.print(" in EEPROM address 2. Name: ");
Serial.print(button3.name);
Serial.print(", Date: ");
Serial.println(button3.date);
}
// Control LED4 with push button 4
if (status4 == HIGH) {
digitalWrite(SKY_LED4, LOW); // Turn off LED4 if button 4 is not pressed
} else {
digitalWrite(SKY_LED4, HIGH); // Turn on LED4 if button 4 is pressed
EEPROM.write(3, 4); // Store data 4 in EEPROM address 3
Serial.print("Button ");
Serial.print(button4.serialNumber);
Serial.print(" pressed: Stored ");
Serial.print(4);
Serial.print(" in EEPROM address 3. Name: ");
Serial.print(button4.name);
Serial.print(", Date: ");
Serial.println(button4.date);
}
// Control LED5 with push button 5
if (status5 == HIGH) {
digitalWrite(GREEN_LED5, LOW); // Turn off LED5 if button 5 is not pressed
} else {
digitalWrite(GREEN_LED5, HIGH); // Turn on LED5 if button 5 is pressed
EEPROM.write(4, 5); // Store data 5 in EEPROM address 4
Serial.print("Button ");
Serial.print(button5.serialNumber);
Serial.print(" pressed: Stored ");
Serial.print(5);
Serial.print(" in EEPROM address 4. Name: ");
Serial.print(button5.name);
Serial.print(", Date: ");
Serial.println(button5.date);
}
delay(100); // Short delay for debouncing
}