Skip to content

Commit d080f09

Browse files
committed
Change to use TeensyDMX library
1 parent 6e03cf0 commit d080f09

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

Deevstock/DSGrid/control_tdmx.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma message Teensy 3.2 + MSGEQ7
2-
#include <TeensyDmx.h>
2+
#include <TeensyDMX.h>
33
//#define MSGEQ7_10BIT
44
// MSGEQ7
55
#include "MSGEQ7.h"
@@ -14,15 +14,16 @@
1414

1515
CMSGEQ7<true, MSGEQ7_RESET_PIN, MSGEQ7_STROBE_PIN, AUDIO_LEFT_PIN, AUDIO_RIGHT_PIN> MSGEQ7;
1616

17-
TeensyDmx Dmx(Serial1);
17+
qindesign::teensydmx::Receiver dmxRx{Serial1};
18+
uint8_t dmxRxBuf[512]; // Buffer up to 512 channels
1819

1920
void InitMSGEQ7() {
2021
MSGEQ7.begin();
2122
}
2223

2324
void controlSetup() {
2425
pinMode(LED_BUILTIN, OUTPUT);
25-
Dmx.setMode(TeensyDmx::DMX_IN);
26+
dmxRx.begin();
2627
pgm = 0;
2728

2829
InitMSGEQ7();
@@ -32,7 +33,7 @@ void controlSetup() {
3233
}
3334

3435
int getValue(int chan, int minV, int maxV) {
35-
return map(Dmx.getBuffer()[(chan - 1)], 0, 255, minV, maxV);
36+
return map(dmxRxBuf[(chan - 1)], 0, 255, minV, maxV);
3637
}
3738

3839

@@ -56,8 +57,11 @@ int right[7];
5657

5758
void controlLoop() {
5859
int gPatternCount = 32; // FIXME
59-
Dmx.loop();
60-
if (Dmx.newFrame()) {
60+
61+
// Read up to 4 bytes (3rd param) starting from channel 1 (2nd param)
62+
// Channel 0 is the start code
63+
int read = dmxRx.read(dmxRxBuf, 1, 4);
64+
if (read == 4) {
6165
EVERY_N_SECONDS( 2 ) {
6266
Serial.printf("Brighness: %u\n", getValue(1, 0, 255)); // Dimmer data for Channel 1
6367
}

Deevstock/DeevstockDMX/DeevstockDMX.ino

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ 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+
qindesign::teensydmx::Receiver dmxRx{Serial1};
40+
uint8_t dmxRxBuf[6]; // Buffer up to 512 channels
4041

4142
CRGB leds[NUM_LEDS];
4243
CRGB ledsAudio[NUM_AUDIO_LEDS];
@@ -204,7 +205,7 @@ void setup() {
204205
/* USB serial */
205206
Serial.begin(115200);
206207

207-
Dmx.setMode(TeensyDmx::DMX_IN);
208+
dmxRx.begin();
208209

209210
pinMode(LED_BUILTIN, OUTPUT);
210211

@@ -238,29 +239,30 @@ elapsedMillis elapsed;
238239
int pattern = 0;
239240
void loop()
240241
{
241-
Dmx.loop();
242-
if (Dmx.newFrame()) {
243-
242+
// Read up to 6 bytes (3rd param) starting from channel 1 (2nd param)
243+
// Channel 0 is the start code
244+
int read = dmxRx.readPacket(dmxRxBuf, 1, 6);
245+
if (read == 6) {
244246
led = !led;
245247
digitalWrite(LED_BUILTIN, led);
246-
int b = Dmx.getBuffer()[0]; // brightness = 1
248+
int b = dmxRxBuf[0]; // brightness = 1
247249
if (b != BRIGHTNESS) {
248250
BRIGHTNESS = b;
249251
FastLED.setBrightness(BRIGHTNESS);
250252
Serial.printf("Brightness: %u\n", BRIGHTNESS);
251253
}
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
254+
STEPS = dmxRxBuf[1]; // steps = 2
255+
SPEEDO = dmxRxBuf[2]; //speed = 3
256+
FADE = dmxRxBuf[3]; // fade = 4
257+
int p = dmxRxBuf[4]; // pattern = 5
256258
pattern = map(p, 0, 255, 0, (gPatternCount - 1));
257259
if(p > (gPatternCount - 1)) {
258260
p = 0;
259261
}
260262
else {
261263
pattern = p;
262264
}
263-
currentPalette = palettes[map(Dmx.getBuffer()[5], 0, 255, 0, (paletteCount - 1))]; // channel 6
265+
currentPalette = palettes[map(dmxRxBuf[5], 0, 255, 0, (paletteCount - 1))]; // channel 6
264266
// EVERY_N_SECONDS( 2 ) {
265267
// Serial.println(p);
266268
// Serial.print("b=");

0 commit comments

Comments
 (0)