@@ -29,13 +29,16 @@ const bool kMatrixSerpentineLayout = true;
29
29
#define USE_OCTOWS2811
30
30
#include < OctoWS2811.h>
31
31
32
- #include < TeensyDmx .h>
32
+ #include < TeensyDMX .h>
33
33
#include < FastLED.h>
34
34
#include < Audio.h>
35
35
36
36
// **********************************************************************************************************
37
37
38
- TeensyDmx Dmx (Serial1);
38
+ namespace teensydmx = qindesign::teensydmx;
39
+
40
+ teensydmx::Receiver dmxRx{Serial1};
41
+ uint8_t dmxRxBuf[513 ]; // Buffer up to 513 channels, including the start code
39
42
40
43
CRGB leds[NUM_LEDS];
41
44
CRGB ledsAudio[NUM_AUDIO_LEDS];
@@ -204,13 +207,13 @@ void setup() {
204
207
/* USB serial */
205
208
Serial.begin (115200 );
206
209
207
- Dmx. setMode (TeensyDmx::DMX_IN );
210
+ dmxRx. begin ( );
208
211
209
212
// pinMode(LED_BUILTIN, OUTPUT); --- BREAKS AUDIO ?!
210
213
211
214
// FastLED.addLeds<CHIPSET, LED_PIN>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
212
215
LEDS.addLeds <OCTOWS2811, RGB>(leds, NUM_LEDS_PER_STRIP);
213
-
216
+
214
217
FastLED.setBrightness (BRIGHTNESS);
215
218
Serial.println (" Setup" );
216
219
@@ -235,36 +238,46 @@ elapsedMillis elapsed;
235
238
// **********************************************************************************************************
236
239
// Main
237
240
// **********************************************************************************************************
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
+ // Note: It's less efficient to read bytes you don't need;
246
+ // this is only here because it was requested to make the
247
+ // code look better. Ideally, you should call
248
+ // `readPacket(buf, 0, size_needed)` instead.
249
+ }
250
+
238
251
int pattern = 0 ;
239
252
void loop ()
240
253
{
241
- Dmx. loop ();
242
- if (Dmx. newFrame ()) {
243
-
254
+ // Read at least to 7 bytes (6 channels) starting from channel 0 (start code)
255
+ int read = newFrame (dmxRx);
256
+ if ( read >= 7 && dmxRxBuf[ 0 ] == 0 ) { // Ensure start code is zero
244
257
led = !led;
245
258
digitalWrite (LED_BUILTIN, led);
246
- int b = Dmx. getBuffer ()[ 0 ]; // brightness = 1
259
+ int b = dmxRxBuf[ 1 ]; // brightness = 1
247
260
if (b != BRIGHTNESS) {
248
261
BRIGHTNESS = b;
249
262
FastLED.setBrightness (BRIGHTNESS);
250
263
Serial.printf (" Brightness: %u\n " , BRIGHTNESS);
251
264
}
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
265
+ STEPS = dmxRxBuf[ 2 ]; // steps = 2
266
+ SPEEDO = dmxRxBuf[ 3 ]; // speed = 3
267
+ FADE = dmxRxBuf[ 4 ]; // fade = 4
268
+ int p = dmxRxBuf[ 5 ]; // pattern = 5
256
269
pattern = map (p, 0 , 255 , 0 , (gPatternCount - 1 ));
257
270
if (p > (gPatternCount - 1 )) {
258
271
p = 0 ;
259
272
}
260
273
else {
261
274
pattern = p;
262
275
}
263
- currentPalette = palettes[map (Dmx. getBuffer ()[ 5 ], 0 , 255 , 0 , (paletteCount - 1 ))]; // channel 6
276
+ currentPalette = palettes[map (dmxRxBuf[ 6 ], 0 , 255 , 0 , (paletteCount - 1 ))]; // channel 6
264
277
265
- RED = Dmx. getBuffer ()[ 6 ];
266
- GREEN = Dmx. getBuffer ()[ 7 ];
267
- BLUE = Dmx. getBuffer ()[ 8 ];
278
+ RED = dmxRxBuf[ 7 ];
279
+ GREEN = dmxRxBuf[ 8 ];
280
+ BLUE = dmxRxBuf[ 9 ];
268
281
269
282
// EVERY_N_SECONDS( 2 ) {
270
283
// Serial.println(p);
0 commit comments