#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define pin constants
const int BUTTON_PIN = 2; // Button connected to digital pin 2
const int GREEN_LED_PIN = 3; // Green LED connected to digital pin 3
const int RED_LED_PIN = 4; // Red LED connected to digital pin 4
// Define LCD I2C address
const int LCD_ADDRESS = 0x27; // Change if necessary
// Create an LCD object
LiquidCrystal_I2C lcd(LCD_ADDRESS, 20, 4);
void setup() {
// Initialize the LCD
lcd.begin(20, 4);
lcd.backlight();
// Set the initial LCD message
lcd.setCursor(0, 0);
lcd.print("Missing Tools:");
// Set pin modes
pinMode(BUTTON_PIN, INPUT); // Button with internal pull-up resistor
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
// Turn on the red LED initially
digitalWrite(RED_LED_PIN, HIGH);
}
void loop() {
// Read the button state
int buttonState = digitalRead(BUTTON_PIN);
// Check the button state
if (buttonState == LOW) { // Button pressed
// Turn on the green LED
digitalWrite(GREEN_LED_PIN, HIGH);
// Turn off the red LED
digitalWrite(RED_LED_PIN, LOW);
// Update the LCD
lcd.setCursor(0, 1);
lcd.print("Tools Found!");
} else { // Button not pressed
// Turn on the red LED
digitalWrite(RED_LED_PIN, HIGH);
// Turn off the green LED
digitalWrite(GREEN_LED_PIN, LOW);
// Update the LCD
lcd.setCursor(0, 1);
lcd.print("Missing Tools:");
}
// Delay for a short time
delay(50);
}