Hello, I am new to Arduino and this is just a learning project I have been working on.
I have a DMX shield (digital stage lighting controller) using the Conceptinetics library. The shield is controlling a fiber optics driver that uses 4 DMX channels and I have 4 linear potentiometers sending input to the Arduino.
The problem is, the code constantly sends DMX values on all 4 channels, every time the loop repeats. I need to find a way to send a DMX value only when the input for that channel has changed. So, I need to be able to send output for channel 1 only when the channel 1 pot is moving and have no output sent on the other 3 channels. i.e. channel 1 pot moves, channel 1 sends new DMX output.
I have tried a few things that didn't work out. Can someone show me an example that may work or point me the right direction. Thank you.
#include <Conceptinetics.h>
#define DMX_MASTER_CHANNELS 100
// Pin number to change read or write mode on the shield
#define RXEN_PIN 2
// Configure a DMX master controller, the master controller
// will use the RXEN_PIN to control its write operation on the bus
DMX_Master dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );
int color = 1; // DMX chan 1, 0 and 255 = no color, 32 = purple, 64 = yellow, 96 = teal,
// 128 = orange, 160 = blue, 192 = pink, 224 = green
int cycle = 2; // DMX chan 2, 0 = off, forward 1 = slow, 127 = fast, 128 to 255?
int fade = 3; // DMX chan 3, 0 = full, 127 = off, 255 = full
int strobe = 4; // DMX chan 4, 0 = off, 1 = slow, 255 = fast
int sensorPin0 = A0;
int sensorPin1 = A1;
int sensorPin2 = A2;
int sensorPin3 = A3;
int dmxval0 = 0;
int dmxval1 = 1;
int dmxval2 = 2;
int dmxval3 = 3;
void setup() {
dmx_master.enable ();
}
void loop()
{
fibercolor();
fibercycle();
fiberfade();
fiberstrobe();
}
void fibercolor()
{
dmxval0 = analogRead(sensorPin0);
dmxval0 = dmxval0 / 4;
dmx_master.setChannelValue ( color, dmxval0 );
}
void fibercycle()
{
dmxval1 = analogRead(sensorPin1);
dmxval1 = dmxval1 / 4;
dmx_master.setChannelValue ( cycle, dmxval1 );
}
void fiberfade()
{
dmxval2 = analogRead(sensorPin2);
dmxval2 = dmxval2 / 4;
dmx_master.setChannelValue ( fade, dmxval2 );
}
void fiberstrobe()
{
dmxval3 = analogRead(sensorPin3);
dmxval3 = dmxval3 / 4;
dmx_master.setChannelValue ( strobe, dmxval3 );
}