Hey guys. I'm finally nearing the final stages of making this 4 button DMX trigger of mine. I'm pretty sure the circuit is correct. The dimmer pack says its receiving a signal, but only after a button is held down. And even then, there seems to be a second or two delay for it to get that signal.
I feel like I'm sending the wrong dmx message to the dimmer pack because even though the DMX SIGNAL light blinks when a button is held, none of the dimmers turn on. Anyone have any ideas?
Intended use of controller: https://drive.google.com/file/d/0B_JgvjO0lMw5WXNOOTFYOUVwcUk/view?usp=sharing
Link to schematic: https://drive.google.com/file/d/0B_JgvjO0lMw5RFNBcFdia3VDTnc/view?usp=sharing
DMX Driver datasheet: https://drive.google.com/file/d/0B_JgvjO0lMw5SEM3UnZEOEpmS3c/view?usp=sharing
Arduino Sketch:
[ Libraries used: Bounce2, Four Universes DMX512 Library]
#include <lib_dmx.h>
#include <Bounce2.h>
// User Settings
#define DEBOUNCE 15 // how many ms to debounce
byte buttons[] = {4, 5, 6, 7}; // Button # and position
#define NUMBUTTONS sizeof(buttons) // Check size of above array
byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
#define DMX512 (0)
int dmxpin = 10; // DMX Driver Control Pin # (MUST BE DIGIAL OUTPUT)
int dmxaddress = 1; // DMX starting address
int dmxchannels = 4; // Number of DMX channels
void check_switches() {
static byte previousstate[NUMBUTTONS];
static byte currentstate[NUMBUTTONS];
static long lasttime;
byte index;
if (millis() < lasttime) { // we wrapped around, lets just try again
lasttime = millis();
}
if ((lasttime + DEBOUNCE) > millis()) { // not enough time has passed to debounce
return;
}
lasttime = millis(); // ok we have waited DEBOUNCE milliseconds, lets reset the timer
for (index = 0; index < NUMBUTTONS; index++) {
currentstate[index] = digitalRead(buttons[index]); // read the button
if (currentstate[index] == previousstate[index]) {
if ((pressed[index] == LOW) && (currentstate[index] == LOW)) { // just pressed
justpressed[index] = 1; //just pressed
}
else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) { // just released
justreleased[index] = 1;
}
pressed[index] = !currentstate[index]; // remember, digital HIGH means NOT pressed
}
previousstate[index] = currentstate[index]; // keep a running tally of the buttons
}
}
void setup() {
byte i;
//SETUP DMX
ArduinoDmx0.set_control_pin (dmxpin);
ArduinoDmx0.set_tx_address (dmxaddress);
ArduinoDmx0.set_tx_channels (dmxchannels);
ArduinoDmx0.init_tx (DMX512);
// Make button # input pins
for (i = 0; i < NUMBUTTONS; i++)
{ pinMode(buttons[i], INPUT);
}
// Run timer2 interrupt every 15 ms
TCCR2A = 0;
TCCR2B = 1 << CS22 | 1 << CS21 | 1 << CS20;
//Timer2 Overflow Interrupt Enable
TIMSK2 |= 1 << TOIE2;
}
SIGNAL(TIMER2_OVF_vect) {
check_switches();
}
void loop() {
// BUTTON CHECK
for (byte i = 0; i < NUMBUTTONS; i++) {
if (justpressed[i]) { // BUTTON JUST PRESSED --------
justpressed[i] = 0;
}
if (justreleased[i]) { // BUTTON RELEASED --------
if (i == 0) { //Button 1 released
ArduinoDmx0.TxBuffer[1] = 0; // DMX off ch 1
}
if (i == 1) { //Button 2 released
ArduinoDmx0.TxBuffer[2] = 0; // DMX off ch 2
}
if (i == 2) { //Button 3 released
ArduinoDmx0.TxBuffer[3] = 0; // DMX off ch 3
}
if (i == 3) { //Button 4 released
ArduinoDmx0.TxBuffer[4] = 0; // DMX off ch 4
}
justreleased[i] = 0; // RESET?
}
if (pressed[i]) { //BUTTON PRESSED --------
if (i == 0) { // If Button 1 PRESSED then,
ArduinoDmx0.TxBuffer[1] = 255; // DMX full power ch 1
}
if (i == 1) { // If Button 2 PRESSED then,
ArduinoDmx0.TxBuffer[2] = 255; // DMX full power ch 2
}
if (i == 2) { // If Button 3 PRESSED then,
ArduinoDmx0.TxBuffer[3] = 255; // DMX full power ch 3
}
if (i == 3) { // If Button 4 PRESSED then,
ArduinoDmx0.TxBuffer[4] = 255; // DMX full power ch 4
}
pressed[i] = 0; // RESET?
}
}
}