Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions Deevstock/DSGrid/control_tdmx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma message Teensy 3.2 + MSGEQ7
#include <TeensyDmx.h>
#include <TeensyDMX.h>
//#define MSGEQ7_10BIT
// MSGEQ7
#include "MSGEQ7.h"
Expand All @@ -14,25 +14,28 @@

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

TeensyDmx Dmx(Serial1);
namespace teensydmx = qindesign::teensydmx;

void InitMSGEQ7() {
teensydmx::Receiver dmxRx{Serial1};
uint8_t dmxRxBuf[513]; // Buffer up to 513 channels, including the start code

void InitMSGEQ7() {
MSGEQ7.begin();
}

void controlSetup() {
pinMode(LED_BUILTIN, OUTPUT);
Dmx.setMode(TeensyDmx::DMX_IN);
dmxRx.begin();
pgm = 0;

InitMSGEQ7();

delay(1000);
Serial.println("Startup");
}

int getValue(int chan, int minV, int maxV) {
return map(Dmx.getBuffer()[(chan - 1)], 0, 255, minV, maxV);
return map(dmxRxBuf[chan], 0, 255, minV, maxV);
}


Expand All @@ -50,10 +53,21 @@ int MSGEQ7get(int band, int channel) {

int led = 0;

// Checks if there's a new DMX frame and returns the frame size.
static int newFrame(teensydmx::Receiver &dmxRx) {
return dmxRx.readPacket(dmxRxBuf, 0, 513);
// Note: It's less efficient to read bytes you don't need;
// this is only here because it was requested to make the
// code look better. Ideally, you should call
// `readPacket(buf, 0, size_needed)` instead.
}

void controlLoop() {
int gPatternCount = 32; // FIXME
Dmx.loop();
if (Dmx.newFrame()) {

// Read at least 5 bytes (4 channels) starting from channel 0 (start code)
int read = newFrame(dmxRx, dmxRxBuf);
if (read >= 5 && dmxRxBuf[0] == 0) { // Ensure start code is zero
EVERY_N_SECONDS( 2 ) {
Serial.printf("Brighness: %u\n", getValue(1, 0, 255)); // Dimmer data for Channel 1
}
Expand Down
43 changes: 28 additions & 15 deletions Deevstock/DeevstockDMX/DeevstockDMX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ const bool kMatrixSerpentineLayout = true;
#define USE_OCTOWS2811
#include<OctoWS2811.h>

#include <TeensyDmx.h>
#include <TeensyDMX.h>
#include <FastLED.h>
#include <Audio.h>

// **********************************************************************************************************

TeensyDmx Dmx(Serial1);
namespace teensydmx = qindesign::teensydmx;

teensydmx::Receiver dmxRx{Serial1};
uint8_t dmxRxBuf[513]; // Buffer up to 513 channels, including the start code

CRGB leds[NUM_LEDS];
CRGB ledsAudio[NUM_AUDIO_LEDS];
Expand Down Expand Up @@ -204,7 +207,7 @@ void setup() {
/* USB serial */
Serial.begin(115200);

Dmx.setMode(TeensyDmx::DMX_IN);
dmxRx.begin();

// pinMode(LED_BUILTIN, OUTPUT); --- BREAKS AUDIO ?!

Expand Down Expand Up @@ -235,36 +238,46 @@ elapsedMillis elapsed;
// **********************************************************************************************************
// Main
// **********************************************************************************************************

// Checks if there's a new DMX frame and returns the frame size.
static int newFrame(teensydmx::Receiver dmxRx) {
return dmxRx.readPacket(dmxRxBuf, 0, 513);
// Note: It's less efficient to read bytes you don't need;
// this is only here because it was requested to make the
// code look better. Ideally, you should call
// `readPacket(buf, 0, size_needed)` instead.
}

int pattern = 0;
void loop()
{
Dmx.loop();
if (Dmx.newFrame()) {

// Read at least to 7 bytes (6 channels) starting from channel 0 (start code)
int read = newFrame(dmxRx);
if (read >= 7 && dmxRxBuf[0] == 0) { // Ensure start code is zero
led = !led;
digitalWrite(LED_BUILTIN, led);
int b = Dmx.getBuffer()[0]; // brightness = 1
int b = dmxRxBuf[1]; // brightness = 1
if (b != BRIGHTNESS) {
BRIGHTNESS = b;
FastLED.setBrightness(BRIGHTNESS);
Serial.printf("Brightness: %u\n", BRIGHTNESS);
}
STEPS = Dmx.getBuffer()[1]; // steps = 2
SPEEDO = Dmx.getBuffer()[2]; //speed = 3
FADE = Dmx.getBuffer()[3]; // fade = 4
int p = Dmx.getBuffer()[4]; // pattern = 5
STEPS = dmxRxBuf[2]; // steps = 2
SPEEDO = dmxRxBuf[3]; //speed = 3
FADE = dmxRxBuf[4]; // fade = 4
int p = dmxRxBuf[5]; // pattern = 5
pattern = map(p, 0, 255, 0, (gPatternCount - 1));
if(p > (gPatternCount - 1)) {
p = 0;
}
else {
pattern = p;
}
currentPalette = palettes[map(Dmx.getBuffer()[5], 0, 255, 0, (paletteCount - 1))]; // channel 6
currentPalette = palettes[map(dmxRxBuf[6], 0, 255, 0, (paletteCount - 1))]; // channel 6

RED = Dmx.getBuffer()[6];
GREEN = Dmx.getBuffer()[7];
BLUE = Dmx.getBuffer()[8];
RED = dmxRxBuf[7];
GREEN = dmxRxBuf[8];
BLUE = dmxRxBuf[9];

// EVERY_N_SECONDS( 2 ) {
// Serial.println(p);
Expand Down