#include <Adafruit_NeoPixel.h>
#include <math.h>
#define PIN_WS2812B 26 // The ESP32 pin GPIO16 connected to WS2812B
#define NUM_PIXELS 64 // The number of LEDs (pixels) on WS2812B LED strip
int area_num = 3, area1 = 16, area2 = 32, area3 = 48, area4 = 64;
int stepTime = 50;
byte leds[][3] = {
{0b10101011, 0b01010100, 0b01000110},
{0b10101011, 0b01010100, 0b01000110},
{0b10101011, 0b01010100, 0b01000110},
{0b10101011, 0b01010100, 0b01000110},
{0b10101011, 0b01010100, 0b01000110},
{0b10101011, 0b01010100, 0b01000110},
{0b10101011, 0b01010100, 0b01000110},
{0b10101011, 0b01010100, 0b01000110}
};
Adafruit_NeoPixel ws2812b(NUM_PIXELS, PIN_WS2812B, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Serial.println("Initializing...");
pinMode (PIN_WS2812B, OUTPUT);
ws2812b.begin(); // initialize WS2812B strip object (REQUIRED)
}
void loop() {
ws2812b.clear();
for (int pixel = 8 - 1; pixel >= 0; pixel--) { // for each pixel
byte resultR = (leds[0][0] >> pixel) & 0x01;
byte resultG = (leds[0][1] >> pixel) & 0x01;
byte resultB = (leds[0][2] >> pixel) & 0x01;
Serial.print("\t pixel: ");
Serial.print( pixel);
Serial.print("\t RGB(");
Serial.print(resultR);
Serial.print(", ");
Serial.print(resultG);
Serial.print(", ");
Serial.print(resultB);
Serial.print(") ");
ws2812b.setPixelColor(pixel, ws2812b.Color(255 * resultR, 255 * resultG, 255 * resultB)); // it only takes effect if pixels.show() is called
ws2812b.show(); // update to the WS2812B Led Strip
delay(stepTime); // 500ms pause between each pixel
Serial.println("");
}
}
void test1() {
// turn pixels to green one-by-one with delay between each pixel
for (int pixel = 0; pixel < area1; pixel++) { // for each pixel
ws2812b.setPixelColor(pixel, ws2812b.Color(255, 0, 0)); // it only takes effect if pixels.show() is called
ws2812b.show(); // update to the WS2812B Led Strip
Serial.print("pixel: ");
Serial.println( pixel);
delay(stepTime); // 500ms pause between each pixel
}
for (int pixel = area2 - 1; pixel >= area1; pixel--) { // for each pixel
ws2812b.setPixelColor(pixel, ws2812b.Color(0, 255, 0)); // it only takes effect if pixels.show() is called
//ws2812b.setPixelColor(pixel, ws2812b.Color(0, 255, 0)); // it only takes effect if pixels.show() is called
ws2812b.show(); // update to the WS2812B Led Strip
Serial.print("\tpixel: ");
Serial.println( pixel);
delay(stepTime); // 500ms pause between each pixel
}
for (int pixel = area2; pixel < area3; pixel++) { // for each pixel
ws2812b.setPixelColor(pixel, ws2812b.Color(0, 0, 255)); // it only takes effect if pixels.show() is called
ws2812b.show(); // update to the WS2812B Led Strip
Serial.print("\t\t pixel: ");
Serial.println( pixel);
delay(stepTime); // 500ms pause between each pixel
}
for (int pixel = area4 - 1; pixel >= area3; pixel--) { // for each pixel
ws2812b.setPixelColor(pixel, ws2812b.Color(0, 255, 0)); // it only takes effect if pixels.show() is called
ws2812b.show(); // update to the WS2812B Led Strip
Serial.print("\tpixel: ");
Serial.println( pixel);
delay(stepTime); // 500ms pause between each pixel
}
/* turn off all pixels for one seconds
ws2812b.clear();
ws2812b.show(); // update to the WS2812B Led Strip
delay(1000); // 1 second off time
*/
}