Created
April 18, 2025 07:45
-
-
Save fieldOfView/26f5d514df6a8b80853a769336279f55 to your computer and use it in GitHub Desktop.
An Arduino sketch that uses Neopixelbus with adjusted timing to control a 20x20 WS2812b LED curtain from Aliexpress
This file contains hidden or 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
#include <NeoPixelBus.h> | |
const static uint16_t PixelCount = 400; | |
const static uint8_t PixelPin = 13; | |
class NeoBitsSpeedWs2812xCurtain : public NeoBitsSpeedBase | |
{ | |
public: | |
const static uint16_t BitSendTimeNs = 1425; | |
const static uint16_t ResetTimeUs = 300; | |
}; | |
typedef NeoEsp32I2sXMethodBase<NeoBitsSpeedWs2812xCurtain, NeoEsp32I2s1Mux8Bus, NeoBitsNotInverted> NeoEsp32I2s1X8Ws2812xCurtainMethod; | |
NeoPixelBus<NeoBgrFeature, NeoEsp32I2s1X8Ws2812xCurtainMethod> strip(PixelCount, PixelPin); | |
void setup() { | |
Serial.begin(115200); | |
while (!Serial); // wait for serial attach | |
Serial.println(); | |
Serial.println("Initializing..."); | |
Serial.flush(); | |
// must call begin on all the strips | |
strip.Begin(); | |
for(int i=0; i<PixelCount; i++) { | |
strip.SetPixelColor(i, getRainbowColor(i - (i/20), PixelCount)); | |
} | |
Serial.println(); | |
Serial.println("Running..."); | |
} | |
void loop() { | |
strip.RotateRight(4); | |
strip.Show(); | |
} | |
RgbColor getRainbowColor(int index, int totalLength) { | |
// Calculate position in rainbow cycle (0 to 360 degrees) | |
float angle = (index * 360.0f / totalLength); | |
// Calculate RGB values based on angle | |
int red = 0; | |
int green = 0; | |
int blue = 0; | |
if (angle < 60) { | |
red = 255; // Red to Yellow | |
green = int(angle * 255 / 60); | |
blue = 0; | |
} else if (angle < 120) { | |
red = int((120 - angle) * 255 / 60); // Yellow to Green | |
green = 255; | |
blue = 0; | |
} else if (angle < 180) { | |
red = 0; // Green to Cyan | |
green = 255; | |
blue = int((angle - 120) * 255 / 60); | |
} else if (angle < 240) { | |
red = 0; // Cyan to Blue | |
green = int((240 - angle) * 255 / 60); | |
blue = 255; | |
} else if (angle < 300) { | |
red = int((angle - 240) * 255 / 60); // Blue to Magenta | |
green = 0; | |
blue = 255; | |
} else { | |
red = 255; // Magenta to Red | |
green = 0; | |
blue = int((360 - angle) * 255 / 60); | |
} | |
return RgbColor(red, green, blue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These are the curtains this works with:
https://nl.aliexpress.com/item/1005007046445393.html