#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define PIN 2
#define NUM_LEDS 24
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 20, 4); // Adjust the I2C address if necessary
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0);
lcd.print("Starting...");
}
void loop() {
lcd.clear();
// Chase clockwise in random colors
lcd.setCursor(0, 0);
lcd.print("Chase clockwise");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, random(0, 256), random(0, 256), random(0, 256));
strip.show();
delay(200);
strip.setPixelColor(i, 0, 0, 0);
}
// Chase anticlockwise in random colors
lcd.setCursor(0, 0);
lcd.print("Chase anticlockwise");
for (int i = NUM_LEDS - 1; i >= 0; i--) {
strip.setPixelColor(i, random(0, 256), random(0, 256), random(0, 256));
strip.show();
delay(200);
strip.setPixelColor(i, 0, 0, 0);
}
// Blink all LEDs three times with red, green and blue color
lcd.setCursor(0, 1);
lcd.print("Blinking LEDs");
for (int j = 0; j < 3; j++) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, (j == 0) ? 255 : 0, (j == 1) ? 255 : 0, (j == 2) ? 255 : 0);
}
strip.show();
delay(500);
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 0, 0);
}
strip.show();
delay(500);
}
// Chase to and fro with random colors for even number of LEDs
lcd.setCursor(0, 2);
lcd.print("Chase to and fro");
for (int i = NUM_LEDS - (NUM_LEDS % 2); i >= NUM_LEDS / 2; i--) {
int j = NUM_LEDS - i - 1;
strip.setPixelColor(i, random(0, 256), random(0, 256), random(0, 256));
strip.setPixelColor(j, random(0, 256), random(0, 256), random(0, 256));
strip.show();
delay(500);
strip.setPixelColor(i, 0, 0, 0);
strip.setPixelColor(j, 0, 0, 0);
delay(500);
// Display a message on the LCD
lcd.setCursor(0, 3);
lcd.print("Animation by arvind");
// You can add more actions and LCD messages as needed
}
}