#include <Adafruit_NeoPixel.h>
#define TIME_CLK 10 // Grundtakt
#define LED_RGB_1 14 // DIN von LED-Ring 1 ist an GPIO 14 angeschlossen
#define LED_RGB_2 12 // DIN von LED-Ring 2 ist an GPIO 12 angeschlossen
#define NUM_PIXELS 16 // Anzahl der LEDs
#define FORWARD 0
#define BACKWARD 1
Adafruit_NeoPixel led_ring_1(NUM_PIXELS, LED_RGB_1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel led_ring_2(NUM_PIXELS, LED_RGB_2, NEO_GRB + NEO_KHZ800);
unsigned char r1 = 0x00;
unsigned char g1 = 0xFF;
unsigned char b = 0x00;
unsigned char r2 = 0xFF;
unsigned char g2 = 0x00;
unsigned char i;
unsigned char time_counter = 0, time_step = 3;
unsigned char led_counter = NUM_PIXELS;
boolean direction = BACKWARD;
void setup() {
led_ring_1.begin();
led_ring_2.begin();
Serial.begin(115200);
Serial.println("RGB-Lauflichter");
Serial.println("=========================================================");
}
void loop() {
time_step = analogRead(13) >> 5;
if (time_counter >= time_step) {
time_counter = 0;
if (led_counter < (NUM_PIXELS - 1)) {
led_counter++;
r1 += 0x10;
g1 -= 0x10;
r2 -= 0x10;
g2 += 0x10;
} else {
led_counter = 0;
r1 = 0x00;
g1 = 0xFF;
r2 = 0xFF;
g2 = 0x00;
if (direction == FORWARD) {
direction = BACKWARD;
} else {
direction = FORWARD;
}
}
if (direction == FORWARD) {
for(i = 0; i < NUM_PIXELS; i++) {
if (i < led_counter) {
led_ring_1.setPixelColor(i, led_ring_1.Color(r1, g1, b));
led_ring_2.setPixelColor(i, led_ring_2.Color(r2, g2, b));
} else {
led_ring_1.setPixelColor(i, led_ring_1.Color(r2, g2, b));
led_ring_2.setPixelColor(i, led_ring_2.Color(r1, g1, b));
}
}
led_ring_1.show();
led_ring_2.show();
} else {
for(i = 0; i < NUM_PIXELS; i++) {
if (i < (NUM_PIXELS - led_counter)) {
led_ring_1.setPixelColor(i, led_ring_1.Color(r2, g2, b));
led_ring_2.setPixelColor(i, led_ring_2.Color(r1, g1, b));
} else {
led_ring_1.setPixelColor(i, led_ring_1.Color(r1, g1, b));
led_ring_2.setPixelColor(i, led_ring_2.Color(r2, g2, b));
}
}
led_ring_1.show();
led_ring_2.show();
}
} else {
time_counter++;
}
delay(TIME_CLK);
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
ring1:GND
ring1:VCC
ring1:DIN
ring1:DOUT
pot1:GND
pot1:SIG
pot1:VCC
ring2:GND
ring2:VCC
ring2:DIN
ring2:DOUT