/****************************************************
https://chatgpt.com/share/a0c8ab01-2ae3-478b-a57f-c429f28a41d5
code plan crteate a code i such a way that the built in rgb leds on board of arduino nanao3
1 wiill blink one by one with basic color red green blue to and fro the
each led wil blink twicee with yellow, cyan,magenta twice
3then all leds will simulteneosly blink 7 times with raibow color
code by arvind patil;created using chatgpt the discusion is given in the link at top
19/08/24
****************************************************************/
#define LED_PIN 2
#define NUM_LEDS 3
// Include the necessary libraries
#include <FastLED.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
CRGB leds[NUM_LEDS];
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
// Initialize the LED strip
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
FastLED.clear();
// Initialize Serial communication
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight();
// Display startup message
Serial.println("Starting LED sequence...");
lcd.setCursor(0, 0);
lcd.print("Starting LED sequence...");
}
void loop() {
// Chase red
displayAction("Chasing Red...");
chaseColor(CRGB::Red);
delay(2000);
// Chase green
displayAction("Chasing Green...");
chaseColor(CRGB::Green);
delay(2000);
// Chase blue
displayAction("Chasing Blue...");
chaseColor(CRGB::Blue);
delay(2000);
// Blink each LED with yellow color twice
displayAction("Blinking Yellow...");
blinkEachColorTwice(CRGB::Yellow);
// Blink each LED with cyan color twice
displayAction("Blinking Cyan...");
blinkEachColorTwice(CRGB::Cyan);
// Blink each LED with magenta color twice
displayAction("Blinking Magenta...");
blinkEachColorTwice(CRGB::Magenta);
// Blink all LEDs simultaneously 7 times with rainbow colors
displayAction("Rainbow Blink 7x...");
blinkRainbowSimultaneously(7);
}
void displayAction(const char* action) {
Serial.println(action);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(action);
}
void chaseColor(CRGB color) {
// Move forward
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = color;
FastLED.show();
delay(500);
leds[i] = CRGB::Black; // Turn off the LED
}
// Move backward
for(int i = NUM_LEDS - 1; i >= 0; i--) {
leds[i] = color;
FastLED.show();
delay(500);
leds[i] = CRGB::Black; // Turn off the LED
}
}
void blinkEachColorTwice(CRGB color) {
for (int i = 0; i < NUM_LEDS; i++) {
// Blink twice
for (int j = 0; j < 2; j++) {
leds[i] = color;
FastLED.show();
delay(250);
leds[i] = CRGB::Black;
FastLED.show();
delay(250);
}
}
}
void blinkRainbowSimultaneously(int times) {
for (int i = 0; i < times; i++) {
// Display rainbow colors
for (int j = 0; j < NUM_LEDS; j++) {
leds[j] = CHSV(j * (255 / NUM_LEDS), 255, 255);
}
FastLED.show();
delay(250);
// Turn off all LEDs
FastLED.clear();
FastLED.show();
delay(250);
}
}