#include <Adafruit_NeoPixel.h>
// Define pin numbers
#define LED_START_PIN 2 // Starting pin for LEDs
#define LED_END_PIN 8 // Ending pin for LEDs (inclusive)
#define NEOPIXEL_PIN 11 // Pin connected to NeoPixel ring
#define NUM_NEOPIXELS 24 // Number of LEDs in NeoPixel ring
// Initialize NeoPixel ring
Adafruit_NeoPixel ring = Adafruit_NeoPixel(NUM_NEOPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Variables for LED chasing directions
bool chase_forward = true;
int current_led = LED_START_PIN;
// Variables for NeoPixel chasing directions
bool ring_forward = true;
int current_ring_led = 0;
void setup() {
// Set up standard LEDs (pins 2 to 8) as outputs
for (int pin = LED_START_PIN; pin <= LED_END_PIN; pin++) {
pinMode(pin, OUTPUT);
}
// Initialize NeoPixel ring
ring.begin();
ring.show(); // Initialize all pixels to 'off'
}
void loop() {
// Chase LEDs on pins 2 to 8
chase_standard_leds();
delay(100); // Adjust delay for desired speed
// Chase NeoPixel ring with rainbow colors
chase_neopixel_ring();
delay(50); // Adjust delay for desired speed
}
void chase_standard_leds() {
// Turn off all LEDs first
for (int pin = LED_START_PIN; pin <= LED_END_PIN; pin++) {
digitalWrite(pin, LOW);
}
// Turn on the current LED
digitalWrite(current_led, HIGH);
// Update LED position
if (chase_forward) {
current_led++;
if (current_led > LED_END_PIN) {
current_led = LED_END_PIN - 1; // Reverse direction
chase_forward = false;
}
} else {
current_led--;
if (current_led < LED_START_PIN) {
current_led = LED_START_PIN + 1; // Reverse direction
chase_forward = true;
}
}
}
void chase_neopixel_ring() {
// Clear all NeoPixel LEDs
ring.clear();
// Set the color for the current LED with a rainbow effect
uint32_t color = ring.ColorHSV((current_ring_led * 65536L / NUM_NEOPIXELS), 255, 255);
ring.setPixelColor(current_ring_led, color);
ring.show();
// Update NeoPixel LED position
if (ring_forward) {
current_ring_led++;
if (current_ring_led >= NUM_NEOPIXELS) {
current_ring_led = NUM_NEOPIXELS - 2; // Reverse direction
ring_forward = false;
}
} else {
current_ring_led--;
if (current_ring_led < 0) {
current_ring_led = 1; // Reverse direction
ring_forward = true;
}
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
led6:A
led6:C
led7:A
led7:C
ring1:GND
ring1:VCC
ring1:DIN
ring1:DOUT