@@ -30,13 +30,16 @@ const bool kMatrixSerpentineLayout = true;
3030#define USE_OCTOWS2811
3131#include < OctoWS2811.h>
3232
33- #include < TeensyDmx .h>
33+ #include < TeensyDMX .h>
3434#include < FastLED.h>
3535#include < Audio.h>
3636
3737// **********************************************************************************************************
3838
39- TeensyDmx Dmx (Serial1);
39+ namespace teensydmx = qindesign::teensydmx;
40+
41+ teensydmx::Receiver dmxRx{Serial1};
42+ uint8_t dmxRxBuf[513 ]; // Buffer up to 513 channels, including the start code
4043
4144CRGB leds[NUM_LEDS];
4245CRGB ledsAudio[NUM_AUDIO_LEDS];
@@ -204,7 +207,7 @@ void setup() {
204207 /* USB serial */
205208 Serial.begin (115200 );
206209
207- Dmx. setMode (TeensyDmx::DMX_IN );
210+ dmxRx. begin ( );
208211
209212 pinMode (LED_BUILTIN, OUTPUT);
210213
@@ -235,32 +238,38 @@ elapsedMillis elapsed;
235238// **********************************************************************************************************
236239// Main
237240// **********************************************************************************************************
241+
242+ // Checks if there's a new DMX frame and returns the frame size.
243+ static int newFrame (teensydmx::Receiver dmxRx) {
244+ return dmxRx.readPacket (dmxRxBuf, 0 , 513 );
245+ }
246+
238247int pattern = 0 ;
239248void loop ()
240249{
241- Dmx. loop ();
242- if (Dmx. newFrame ()) {
243-
250+ // Read at least to 7 bytes (6 channels) starting from channel 0 (start code)
251+ int read = newFrame (dmxRx);
252+ if (read >= 7 && dmxRxBuf[ 0 ] == 0 ) { // Ensure start code is zero
244253 led = !led;
245254 digitalWrite (LED_BUILTIN, led);
246- int b = Dmx. getBuffer ()[ 0 ]; // brightness = 1
255+ int b = dmxRxBuf[ 1 ]; // brightness = 1
247256 if (b != BRIGHTNESS) {
248257 BRIGHTNESS = b;
249258 FastLED.setBrightness (BRIGHTNESS);
250259 Serial.printf (" Brightness: %u\n " , BRIGHTNESS);
251260 }
252- STEPS = Dmx. getBuffer ()[ 1 ]; // steps = 2
253- SPEEDO = Dmx. getBuffer ()[ 2 ]; // speed = 3
254- FADE = Dmx. getBuffer ()[ 3 ]; // fade = 4
255- int p = Dmx. getBuffer ()[ 4 ]; // pattern = 5
261+ STEPS = dmxRxBuf[ 2 ]; // steps = 2
262+ SPEEDO = dmxRxBuf[ 3 ]; // speed = 3
263+ FADE = dmxRxBuf[ 4 ]; // fade = 4
264+ int p = dmxRxBuf[ 5 ]; // pattern = 5
256265 pattern = map (p, 0 , 255 , 0 , (gPatternCount - 1 ));
257266 if (p > (gPatternCount - 1 )) {
258267 p = 0 ;
259268 }
260269 else {
261270 pattern = p;
262271 }
263- currentPalette = palettes[map (Dmx. getBuffer ()[ 5 ], 0 , 255 , 0 , (paletteCount - 1 ))]; // channel 6
272+ currentPalette = palettes[map (dmxRxBuf[ 6 ], 0 , 255 , 0 , (paletteCount - 1 ))]; // channel 6
264273// EVERY_N_SECONDS( 2 ) {
265274// Serial.println(p);
266275// Serial.print("b=");
0 commit comments