/**************************************************************************
The provided code is for controlling a NeoPixel ring with 12 LEDs
connected to an Arduino. It implements a specific blinking pattern
using rainbow colors. Here's a summary of the code's functionality:
1. The code initializes the NeoPixel ring and sets all LEDs to an off state.
2. In the `loop()` function, the code defines the blinking pattern for
different sets of LEDs.
3. The first LED blinks three times.
4. The first two LEDs blink three times.
5. The first three LEDs blink three times.
6. The first four LEDs blink three times.
7. The code then continues the pattern up to the first twelve LEDs,
with each set blinking three times.
8. The `blinkLED()` function is used to control the blinking of a specified
range of LEDs with a given delay.
9. The `Wheel()` function generates rainbow colors based on the LED index.
10. The code uses the `Adafruit_NeoPixel` library, so make sure i
t is installed in the Arduino IDE.
Remember to adjust the LED pin and wiring configuration according to your setup.
by arvind patil 30may 2023
************************************************************************/
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define LED_COUNT 12
Adafruit_NeoPixel ring(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
ring.begin();
ring.show(); // Initialize all pixels to off
}
void loop() {
// Blinking the first LED three times
blinkLED(0, 3, 1000); // LED index, number of blinks, delay in milliseconds
// Blinking the first two LEDs three times
blinkLED(0, 6, 1000);
// Blinking the first three LEDs three times
blinkLED(0, 9, 1000);
// Blinking the first four LEDs three times
blinkLED(0, 12, 1000);
// Continue the pattern up to the first twelve LEDs
for (int i = 0; i < LED_COUNT; i++) {
blinkLED(0, i + 1, 1000);
}
}
void blinkLED(int startIndex, int numLEDs, int delayTime) {
// Set the color for the LEDs in the specified range
for (int i = startIndex; i < startIndex + numLEDs; i++) {
ring.setPixelColor(i, Wheel(i * 256 / LED_COUNT));
}
// Turn on the specified LEDs
ring.show();
delay(delayTime);
// Turn off the specified LEDs
for (int i = startIndex; i < startIndex + numLEDs; i++) {
ring.setPixelColor(i, 0);
}
ring.show();
delay(delayTime);
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return ring.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return ring.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return ring.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}