// Project: LED Control with LCD and NeoPixel Ring
// Author: Arvind Patil
// Date: 9th July 2023
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
#include <Adafruit_NeoPixel.h> // Library for NeoPixel
#define LED_PIN 2 // Pin for controlling LED
#define NEOPIXEL_PIN 4 // Pin for controlling NeoPixel ring
#define NUM_PIXELS 12 // Number of NeoPixels in the ring
LiquidCrystal_I2C lcd(0x27, 20, 4); // LCD object with I2C address 0x27
Adafruit_NeoPixel pixels(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
lcd.begin(20, 4); // Initialize the LCD
lcd.print("LED Control"); // Print initial text on LCD
lcd.setCursor(0, 2);
lcd.println("action on lcd ");
lcd.setCursor(9, 3);
lcd.print("by Arvind ");
pinMode(LED_PIN, OUTPUT); // Set LED pin as OUTPUT
pixels.begin(); // Initialize the NeoPixel ring
pixels.setBrightness(250); // Set NeoPixel brightness (0-255)
pixels.show(); // Update NeoPixel ring
}
void loop() {
digitalWrite(LED_PIN, HIGH); // Turn LED on
lcd.setCursor(0, 1);
lcd.print("LED ON ");
rainbowChase(50, 100); // Run the rainbow chase effect
delay(2000); // Delay 1 second
digitalWrite(LED_PIN, LOW); // Turn LED off
lcd.setCursor(0, 1);
lcd.print("LED OFF ");
rainbowChase(50, -100); // Run the reverse rainbow chase effect
delay(2000); // Delay 1 second
}
// Function to perform a rainbow chase effect on the NeoPixel ring
void rainbowChase(uint8_t wait, int8_t direction) {
for (int i = 0; i < NUM_PIXELS; i++) {
pixels.setPixelColor((i + direction) % NUM_PIXELS, pixels.ColorHSV(i * 65536 / NUM_PIXELS));
pixels.show();
delay(wait);
pixels.setPixelColor((i + direction) % NUM_PIXELS, 0);
}
}
Downloaded code from https://wokwi.com/projects/369746768427895809
अरविन्द पाटील 21/11/23 .