#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#define PIN 6 // Choose a digital pin on the Arduino Uno
#define NUM_PIXELS 8
Adafruit_NeoPixel np = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
np.begin(); // Initialize the NeoPixel library
lcd.init(); // Initialize the LCD library
lcd.backlight(); // Turn on the LCD backlight
Serial.begin(9600); // Initialize the serial communication
}
void clearLCD() {
lcd.clear(); // Clear the LCD display
delay(100); // Small delay for clearing to take effect
}
void loop() {
if (Serial.available() > 0) {
char a = Serial.read();
Serial.print("Input received: ");
Serial.println(a);
if (a == 'a') {
clearLCD();
lcd.setCursor(0, 0); // Move cursor to the first row, first column
lcd.print("No elephant");
for (int i = 0; i < 8; i++) {
np.setPixelColor(i, np.Color(103, 189, 170)); // Set pixels to green
}
np.show(); // Write the data to the pixels
delay(500); // Wait for 0.5 seconds
} else if (a == 'b') {
clearLCD();
lcd.setCursor(0, 0); // Move cursor to the first row, first column
lcd.print("Elephant ahead!");
for (int i = 0; i < 8; i++) {
np.setPixelColor(i, np.Color(175, 54, 60)); // Set pixels to red
}
np.show(); // Write the data to the pixels
delay(500); // Wait for 0.5 seconds
} else if (a == 'c') {
clearLCD();
lcd.setCursor(0, 0); // Move cursor to the first row, first column
lcd.print("Alert mode");
for (int i = 0; i < 8; i++) {
np.setPixelColor(i, np.Color(231, 199, 31)); // Set pixels to yellow
}
np.show(); // Write the data to the pixels
delay(500); // Wait for 0.5 seconds
} else {
clearLCD();
lcd.setCursor(0, 0); // Move cursor to the first row, first column
lcd.print("Invalid input");
for (int i = 0; i < 8; i++) {
np.setPixelColor(i, np.Color(0, 0, 0)); // Turn off LEDs
}
np.show(); // Write the data to the pixels
delay(1500); // Wait for 1.5 seconds
}
}
}