/*******************************************************************************
to a arduino board 10 leds are connected to pin 3 to 12 and data pin
of neopixle 24leds is connected to pin 2writea code to chase the leds
from right to left then left to write delay 1000ms,also chase the all
rgb leds clockwise and anticlockwise using random colors repeat the action
The code uses the digitalWrite function to turn the individual LEDs on
and off to create a chasing effect from right to left and left to right.
For the Neopixel strip, the code uses the setPixelColor and show
functions to set the color of each pixel and display it on the strip.
The random function is used to generate random values for the RGB values
of the Neopixel strip. The delay of 100 milliseconds is used to slow down
the chasing effect so it's easier to see.
author arvind patil 19 march 2023
*********************************************************************************/
#include <Adafruit_NeoPixel.h>
#define LED_PIN 2
#define LED_COUNT 24
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
for (int i = 3; i <= 12; i++) {
pinMode(i, OUTPUT);
}
strip.begin();
strip.show();
}
void loop() {
// Chase LEDs from right to left
for (int i = 12; i >= 3; i--) {
digitalWrite(i, HIGH);
delay(100);
digitalWrite(i, LOW);
}
delay(500);
// Chase LEDs from left to right
for (int i = 3; i <= 12; i++) {
digitalWrite(i, HIGH);
delay(100);
digitalWrite(i, LOW);
}
delay(500);
// Chase all RGB LEDs clockwise
for (int i = 0; i < LED_COUNT; i++) {
strip.setPixelColor(i, random(256), random(256), random(256));
strip.show();
delay(100);
strip.setPixelColor(i, 0, 0, 0);
}
delay(500);
// Chase all RGB LEDs anticlockwise
for (int i = LED_COUNT - 1; i >= 0; i--) {
strip.setPixelColor(i, random(256), random(256), random(256));
strip.show();
delay(100);
strip.setPixelColor(i, 0, 0, 0);
}
delay(1000);
}