#include <Adafruit_NeoPixel.h>
// ESP ---> top A D-in
// base A D-out ---> base B D-in
// top B D-out ----> C left D-in
//
// TOP/FRONT
//
// A Din [-- C --Din] <------- B(Dout)
// / | \
// / |_______[esp32] \
// / \
// A Dout ----------------------------------B Din
//
// BASE/REAR
const int Strip1_NUM_LEDS = 43;
const int Strip1_Pin = 5;
const int Strip1AStart = 0;
const int Strip1BStart = 15;
const int Strip1CStart = 30;
const int Strip1ALEN = 15;
const int Strip1BLEN = 15;
const int Strip1CLEN = 13;
const int Strip2AStart = 0;
const int Strip2BStart = 15;
const int Strip2CStart = 30;
const int Strip2ALEN = 15;
const int Strip2BLEN = 15;
const int Strip2CLEN = 10;
const int Strip2_NUM_LEDS = 43;
const int Strip2_Pin = 4;
Adafruit_NeoPixel Strip1leds(Strip1_NUM_LEDS, Strip1_Pin, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel Strip2leds(Strip2_NUM_LEDS, Strip2_Pin, NEO_GRB + NEO_KHZ800);
// Wave one direction on strip2B and then wave back x number of times
void colorWaveStrip2Bleds(uint32_t c, uint8_t wait, uint32_t reps ) {
for(uint8_t x=reps; x>0; x--){
for(uint16_t i=Strip2BStart; i< Strip2BStart+Strip2BLEN; i++) {
Strip2leds.setPixelColor(i, c);
Strip2leds.setPixelColor(i - 1 , Strip1leds.Color(0, 0, 0));
Strip2leds.show();
delay(wait);
}
for(uint16_t i=Strip2CStart-1; i> Strip2BStart; i--) {
Strip2leds.setPixelColor(i, c);
Strip2leds.setPixelColor(i + 1, Strip1leds.Color(0, 0, 0));
Strip2leds.show();
delay(wait);
}
}
}
// Fill the dots one after the other with a color
void colorWipeStrip1leds(uint32_t c, uint8_t wait ) {
for(uint16_t i=0; i< Strip1leds.numPixels(); i++) {
Strip1leds.setPixelColor(i, c);
Strip1leds.show();
delay(wait);
}
}
void colorWipeStrip2leds(uint32_t c, uint8_t wait ) {
for(uint16_t i=0; i< Strip2leds.numPixels(); i++) {
Strip2leds.setPixelColor(i, c);
Strip2leds.show();
delay(wait);
}
}
void faderToBlackStrip1()
{
for(int j=0; j<Strip1_NUM_LEDS; j++) {
fadeToBlackStrip1(j, 64 );
}
}
void fadeToBlackStrip1(int ledNo, byte fadeValue) {
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = Strip1leds.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
Strip1leds.setPixelColor(ledNo, r,g,b);
}
// Fill the dots one way, and other way
void colorWipeStrip1ABleds(uint32_t c, uint8_t wait ) {
int x= 0;
for(uint16_t i=Strip1AStart; i< Strip1ALEN; i++) {
Strip1leds.setPixelColor(i, c);
// since they are the same length
x=(Strip1BStart + Strip1BLEN -1)- i;
Strip1leds.setPixelColor(x, c);
Strip1leds.show();
delay(wait);
}
}
// Cylon Strip 1 A and B
void cylonStrip1ABleds(uint32_t c, uint8_t wait ) {
int x= 0;
int i =0;
for( i=Strip1ALEN + Strip1AStart ; i >= Strip1AStart ; i--) {
Strip1leds.setPixelColor(i-1, c);
Strip1leds.setPixelColor(i , Strip1leds.Color(0, 0, 0));
// since they are the same length 15
x=((Strip1BStart + Strip1BLEN -1) - i) ;
Strip1leds.setPixelColor(x, c);
Strip1leds.setPixelColor(x - 1 , Strip1leds.Color(0, 0, 0));
Strip1leds.show();
delay(wait);
}
Strip1leds.setPixelColor(Strip1BStart + Strip1BLEN-1 , Strip1leds.Color(0, 0, 0));
Strip1leds.setPixelColor(Strip1AStart , Strip1leds.Color(0, 0, 0));
}
// Cylon Strip 1 C outside to centre
void cylonStrip1C_O2C_leds(uint32_t c, uint8_t wait ) {
int x= 0;
int i =0;
int halfset = Strip1CLEN/2;
for( i= Strip1CStart ; i <= (Strip1CStart -1 )+halfset ; i++) {
Strip1leds.setPixelColor(i, c);
Strip1leds.setPixelColor(i -1 , Strip1leds.Color(0, 0, 0));
// since they are the same length 15
x=((Strip1CStart + Strip1CLEN -1) -( i-Strip1CStart)) ;
Strip1leds.setPixelColor(x, c);
Strip1leds.setPixelColor(x + 1 , Strip1leds.Color(0, 0, 0));
Strip1leds.show();
delay(wait);
}
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 -1 , Strip1leds.Color(0, 0, 0));
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 +1 , Strip1leds.Color(0, 0, 0));
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 , c);
Strip1leds.show();
delay(wait);
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 , Strip1leds.Color(0, 0, 0));
Strip1leds.show();
}
// Cylon Strip 1 A and B Trail
void cylonStrip1ABledsTrail(uint32_t c, uint8_t wait ) {
int x= 0;
int i =0;
for( i=Strip1ALEN + Strip1AStart ; i >= Strip1AStart ; i--) {
Strip1leds.setPixelColor(i-1, c);
// since they are the same length 15
x=((Strip1BStart + Strip1BLEN -1) - i) ;
Strip1leds.setPixelColor(x, c);
faderToBlackStrip1();
Strip1leds.show();
delay(wait);
}
Strip1leds.setPixelColor(Strip1BStart + Strip1BLEN-1 , Strip1leds.Color(0, 0, 0));
Strip1leds.setPixelColor(Strip1AStart , Strip1leds.Color(0, 0, 0));
}
// Cylon Strip 1 C outside to centre Trail
void cylonStrip1C_O2C_ledsTrail(uint32_t c, uint8_t wait ) {
int x= 0;
int i =0;
int halfset = Strip1CLEN/2;
for( i= Strip1CStart ; i <= (Strip1CStart -1 )+halfset ; i++) {
Strip1leds.setPixelColor(i, c);
// since they are the same length 15
x=((Strip1CStart + Strip1CLEN -1) -( i-Strip1CStart)) ;
Strip1leds.setPixelColor(x, c);
faderToBlackStrip1();
Strip1leds.show();
delay(wait);
}
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 -1 , Strip1leds.Color(0, 0, 0));
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 +1 , Strip1leds.Color(0, 0, 0));
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 , c);
Strip1leds.show();
delay(wait);
Strip1leds.setPixelColor(Strip1CStart + Strip1CLEN/2 , Strip1leds.Color(0, 0, 0));
Strip1leds.show();
}
void setup() {
Serial.begin(9600);
Strip1leds.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
Strip1leds.show(); // Turn OFF all pixels ASAP
Strip1leds.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255)
Strip2leds.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
Strip2leds.show(); // Turn OFF all pixels ASAP
Strip2leds.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255)
Serial.println("OK");
for ( int y=0; y< Strip1_NUM_LEDS; y++)
{
Strip1leds.setPixelColor(y, Strip1leds.Color(255, 0, 255));
}
Strip1leds.show();
delay(500);
for ( int y=0; y< Strip1_NUM_LEDS; y++)
{
Strip1leds.setPixelColor(y, Strip1leds.Color(0, 0, 0));
}
Strip1leds.show();
Serial.println("OK Done colour");
}
void loop() {
for (int speed=50;speed> 1;speed =speed-5)
{
cylonStrip1ABleds(Strip1leds.Color(255, 0, 0), speed);
cylonStrip1C_O2C_leds(Strip1leds.Color(255, 0, 0), speed);
}
for (int speed=50;speed> 1;speed =speed-5)
{
cylonStrip1ABledsTrail(Strip1leds.Color(0, 0, 255), speed);
cylonStrip1C_O2C_ledsTrail(Strip1leds.Color(0, 0, 255), speed);
}
for (int speed=50;speed>1;speed = speed-5)
{
colorWaveStrip2Bleds(Strip2leds.Color(0, 0, 255), speed, 2);
}
/*
Serial.println("1st swipe");
colorWipeStrip1leds(Strip1leds.Color(255, 0, 0), 10); // Red
colorWipeStrip2leds(Strip2leds.Color(255, 0, 0), 10); // Red
Serial.println("2nd swipe");
colorWipeStrip1leds(Strip2leds.Color( 0, 255, 0), 5); // Green
colorWipeStrip1leds(Strip2leds.Color( 0, 0, 255), 5); // Blue
Serial.println("3rd swipe");
colorWipeStrip2leds(Strip1leds.Color( 0, 255, 0), 5); // Green
colorWipeStrip2leds(Strip1leds.Color( 0, 0, 255), 5); // Blue
*/
}