Created
July 3, 2021 14:26
-
-
Save codecat/6126ff59a0d24a6b86d4d9f89336efa2 to your computer and use it in GitHub Desktop.
Teensy program for my LED strips.
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
/* | |
Required Connections | |
-------------------- | |
pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips. | |
pin 14: LED strip #2 All 8 are the same length. | |
pin 7: LED strip #3 | |
pin 8: LED strip #4 A 100 ohm resistor should used | |
pin 6: LED strip #5 between each Teensy pin and the | |
pin 20: LED strip #6 wire to the LED strip, to minimize | |
pin 21: LED strip #7 high frequency ringining & noise. | |
pin 5: LED strip #8 | |
*/ | |
#include <OctoWS2811.h> | |
const int ledsPerStrip = 300; | |
DMAMEM uint32_t displayMemory[ledsPerStrip * 6]; | |
uint8_t writeMemory[ledsPerStrip * 3]; | |
OctoWS2811 leds(ledsPerStrip, displayMemory, nullptr, WS2811_GRB | WS2811_800kHz); | |
void setup() | |
{ | |
pinMode(LED_BUILTIN, OUTPUT); | |
leds.begin(); | |
for (int i = 0; i < leds.numPixels(); i++) { | |
leds.setPixel(i, 0); | |
} | |
leds.show(); | |
} | |
void loop() | |
{ | |
bool dirty = false; | |
digitalWrite(LED_BUILTIN, LOW); | |
while (Serial.available()) { | |
digitalWrite(LED_BUILTIN, HIGH); | |
int chan = Serial.read(); | |
int cmd = Serial.read(); | |
uint16_t len = 0; | |
Serial.readBytes((char*)&len, 2); | |
// Set 8 bit pixels | |
if (cmd == 0) { | |
if (len > sizeof(writeMemory)) { | |
len = sizeof(writeMemory); | |
} | |
Serial.readBytes((char*)writeMemory, len); | |
for (int i = 0; i < len / 3; i++) { | |
leds.setPixel( | |
chan * ledsPerStrip + i, | |
writeMemory[i * 3 + 0], | |
writeMemory[i * 3 + 1], | |
writeMemory[i * 3 + 2] | |
); | |
} | |
dirty = true; | |
} | |
} | |
if (dirty) { | |
leds.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment