Created
August 26, 2020 13:40
-
-
Save peacepenguin/171716fbd29a41b1ec2d50ad72fe3b69 to your computer and use it in GitHub Desktop.
neopixel bus multipin output using buffer blt layoutmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test parallel output on multiple pins on ESP32 using RMT technique against RGB fans (ws2812b leds) | |
// 8 channels (pins) are possible with this ESP32 RMT method. | |
#include <NeoPixelBus.h> | |
#include <arduino.h> | |
// manually configure these params: | |
const uint16_t strip01_PixelCount = 18; | |
const uint8_t strip01_PixelPin = 2; | |
const uint16_t strip02_PixelCount = 18; | |
const uint8_t strip02_PixelPin = 13; | |
// calculate total pixel count for use later: | |
const uint16_t totalPixelCount = strip01_PixelCount + strip02_PixelCount; | |
// these are the "output" objects, but we'll use a "buffer" to collect the led color info, then assign peices of the buffer to these real pins: | |
NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt0Ws2812xMethod> strip01(strip01_PixelCount, strip01_PixelPin); | |
NeoPixelBus<NeoGrbFeature, NeoEsp32Rmt1Ws2812xMethod> strip02(strip02_PixelCount, strip02_PixelPin); | |
// create the "input" LED array to store the LED data, use the "buffer" method so the LEDs array can be used later: | |
// wants name, width, height, pixels | |
// | |
// The buffer is a bitmap. so it has a height, width. Our use case is a single "strip" of leds put together by WLED | |
// so the width of this bitmap really represents our total pixel count: | |
// | |
NeoBuffer<NeoBufferMethod<NeoGrbFeature>> strip00(totalPixelCount,1,NULL); | |
#define colorSaturation 128 | |
RgbColor red(colorSaturation, 0, 0); | |
RgbColor green(0, colorSaturation, 0); | |
RgbColor blue(0, 0, colorSaturation); | |
RgbColor white(colorSaturation); | |
RgbColor black(0); | |
HslColor hslRed(red); | |
HslColor hslGreen(green); | |
HslColor hslBlue(blue); | |
HslColor hslWhite(white); | |
HslColor hslBlack(black); | |
// create a new layout map for later use to move the buffer pixels out to NeoPixelBus objects | |
// in our case, width is equal to total pixel count, and height is 1, since its not a panel. | |
// create a "NeoTopology" object, named "topo" that defines a qty to fill into. | |
// This is measured in pixels, so the first entry is "1", instead of "0" as used the coordinate system. | |
NeoTopology<RowMajorLayout> topo(totalPixelCount, 1); | |
uint16_t LayoutMap(int16_t x, int16_t y) | |
{ | |
return topo.MapProbe(x, y); | |
} | |
void setup() | |
{ | |
// required init: | |
strip01.Begin(); | |
strip02.Begin(); | |
// reset them to off: | |
strip01.Show(); | |
strip02.Show(); | |
// set the entire buffer to black color to set off for all pixels: | |
strip00.ClearTo(black); | |
} | |
void loop() | |
{ | |
// assign color to the buffer object LEDs instead: (notice the x/y coordiinate, just use 0 since we're using a "single row" bitmap) | |
strip00.SetPixelColor(35,0, red); | |
strip00.SetPixelColor(34,0, red); | |
strip00.SetPixelColor(33,0, red); | |
strip00.SetPixelColor(32,0, red); | |
strip00.SetPixelColor(31,0, red); | |
strip00.SetPixelColor(30,0, red); | |
strip00.SetPixelColor(29,0, white); | |
strip00.SetPixelColor(28,0, white); | |
strip00.SetPixelColor(27,0, white); | |
strip00.SetPixelColor(26,0, white); | |
strip00.SetPixelColor(25,0, white); | |
strip00.SetPixelColor(24,0, white); | |
strip00.SetPixelColor(23,0, green); | |
strip00.SetPixelColor(22,0, green); | |
strip00.SetPixelColor(21,0, green); | |
strip00.SetPixelColor(20,0, green); | |
strip00.SetPixelColor(19,0, green); | |
strip00.SetPixelColor(18,0, green); | |
strip00.SetPixelColor(17,0, red); | |
strip00.SetPixelColor(16,0, green); | |
strip00.SetPixelColor(15,0, blue); | |
strip00.SetPixelColor(14,0, white); | |
strip00.SetPixelColor(13,0, red); | |
strip00.SetPixelColor(12,0, green); | |
strip00.SetPixelColor(11,0, blue); | |
strip00.SetPixelColor(10,0, white); | |
strip00.SetPixelColor(9,0, red); | |
strip00.SetPixelColor(8,0, green); | |
strip00.SetPixelColor(7,0, blue); | |
strip00.SetPixelColor(6,0, white); | |
strip00.SetPixelColor(5,0, red); | |
strip00.SetPixelColor(4,0, green); | |
strip00.SetPixelColor(3,0, blue); | |
strip00.SetPixelColor(2,0, white); | |
strip00.SetPixelColor(1,0, red); | |
strip00.SetPixelColor(0,0, green); | |
// now we need to divy out the pixels from the buffer (NeoBuffer object) to the actual strips (NeoPixelBus objects) | |
// use the more complicated form of the Blt method: https://github.com/Makuna/NeoPixelBus/wiki/NeoBuffer-object | |
// send pixels from strip00 using Blt, to strip01, starting at buffer index 0,0 (width,height coordinate of starting pixel), to strip01's starting coordinate 0,0, consisting of: 18 pixels wide, 1 pixel tall. | |
// using the LayoutMap | |
strip00.Blt(strip01, 0, 0, 0, 0, strip01_PixelCount, 1, LayoutMap); | |
// send pixels from strip00 using Blt, to strip02, starting at buffer index 18,0 (width,height coordinate of starting pixel), to strip01's starting coordinate 0,0 consisting of: 18 pixels wide, 1 pixel tall, using the layoutmap. | |
strip00.Blt(strip02, 18, 0, 0, 0, 18, 1, LayoutMap); | |
strip01.Show(); | |
strip02.Show(); | |
delay(2000); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment