/**********************************************************************************
In this version, I've removed the neopixel code and replaced it with code
that initializes the 10 LEDs connected to pins 3-12 as standard LEDs.
The loop that chases the LEDs from right to left and left to right now
uses digitalWrite() to turn on and off each LED, instead of strip.
setPixelColor() and strip.show(). The rest of the code remains
the same as before.
author arvind patil 19 march 2023
*********************************************************************************/
#include <Adafruit_NeoPixel.h>
// Define constants for number of LEDs and pin numbers
const int NUM_LEDS = 24;
const int LED_PIN = 2;
const int LED_START = 3;
const int LED_END = 12;
// Create an Adafruit_NeoPixel object
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize the LED strip
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// Initialize LEDs on pins 3 to 12
for (int i = LED_START; i <= LED_END; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
}
void loop() {
// Chase LEDs from right to left
for (int i = LED_START; i <= LED_END; i++) {
digitalWrite(i, HIGH); // Turn on LED
delay(100); // Wait 1 second
digitalWrite(i, LOW); // Turn off LED
}
// Chase LEDs from left to right
for (int i = LED_END; i >= LED_START; i--) {
digitalWrite(i, HIGH); // Turn on LED
delay(100); // Wait 1 second
digitalWrite(i, LOW); // Turn off LED
}
// Chase RGB LEDs clockwise and counterclockwise with random colors
for (int i = 0; i < 24; i++) {
uint32_t color = strip.Color(random(256), random(256), random(256)); // Generate random color
strip.setPixelColor(i, color); // Set LED color
strip.setPixelColor(NUM_LEDS - i - 1, color); // Set opposite LED color
}
strip.show(); // Update LED strip
delay(1000); // Wait 1 second
}