Hey Guys
This is my first attempt at Arduino so I guess its all a learning curve but I’ve been stuck on this for a while now and I would greatly appreciate some help. Long story short, I have an Arduino Uno and a DMX shield attached to it and I want to trigger different DMX signals by different buttons mapped to the Digital Pins.
I can send desired DMX signals from my Arduino and receive them on my light but I am having trouble triggering them individually with a momentary button.
At the current moment I have two buttons attached to the unit (one to Digital Pins 5 and the other to pin 6). I want each button to play a different colour sequence. At the moment the button attached to Pin 5 I want it to go through, Green, Blue, Red and the one on pin 6 I want it to play a wash of Yellow, then Red, then Blue.
However when I push the button it will randomly play either a sequence. Sometimes it will play the correct sequence but other times it won’t. I’m fairly certain the problem is within my code so I’ve attached it below and would appreciate it if someone could tell me where I’m going wrong.
Thanks for your time
#include <Conceptinetics.h> //To talk to my DMX Sheild
#define DMX_MASTER_CHANNELS 8
#define RXEN_PIN 2
const int buttononePin = 5; //Button imput one (Pins 2,3,4 are used to transmit DMX signals)
const int buttontwoPin = 6; // Button imput two
int buttonState = 0; // variable for reading the pushbutton status
// 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 );
void setup()
{
// Enable DMX master interface and start transmitting
dmx_master.enable ();
dmx_master.setChannelRange ( 2, 25, 127 );
pinMode(buttononePin, INPUT);
pinMode(buttontwoPin, INPUT);
}
void loop()
// At the moment these numbers are just place holders.
// Button 1 - Triggers: Green, Blue, Red
{
{
buttonState = digitalRead(buttononePin);
if (buttonState == HIGH)
{
// FYI Channel 1 is brightness, 2 is reds, 3 Greens, 4 Blues, 5 Whites...(I dont want to use channels 6-8 but they are) 6 Strobe, 7 Mode, 8 Hold.
dmx_master.setChannelValue ( 1, 100 );
dmx_master.setChannelValue ( 2, 0);
dmx_master.setChannelValue ( 3, 250 );
dmx_master.setChannelValue ( 4, 10 );
dmx_master.setChannelValue ( 5, 10);
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
delay ( 500 );
dmx_master.setChannelValue ( 1, 100 );
dmx_master.setChannelValue ( 2, 0);
dmx_master.setChannelValue ( 3, 0 );
dmx_master.setChannelValue ( 4, 250 );
dmx_master.setChannelValue ( 5, 10);
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
delay ( 500 );
dmx_master.setChannelValue ( 1, 100 );
dmx_master.setChannelValue ( 2, 250);
dmx_master.setChannelValue ( 3, 0 );
dmx_master.setChannelValue ( 4, 10 );
dmx_master.setChannelValue ( 5, 10);
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
delay ( 1000 );
}
else
{
// turn DMX off:
dmx_master.setChannelValue ( 1, 0 );
dmx_master.setChannelValue ( 2, 0 );
dmx_master.setChannelValue ( 3, 0 );
dmx_master.setChannelValue ( 4, 0 );
dmx_master.setChannelValue ( 5, 0 );
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
}
}
// Button 2 - Triggers: Yellow, Red, Blue.
{
buttonState = digitalRead(buttontwoPin);
if (buttonState == HIGH)
{
dmx_master.setChannelValue ( 1, 100 );
dmx_master.setChannelValue ( 2, 250 );
dmx_master.setChannelValue ( 3, 125 );
dmx_master.setChannelValue ( 4, 0 );
dmx_master.setChannelValue ( 5, 0);
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
delay ( 1000 );
dmx_master.setChannelValue ( 1, 100 );
dmx_master.setChannelValue ( 2, 250 );
dmx_master.setChannelValue ( 3, 0 );
dmx_master.setChannelValue ( 4, 0 );
dmx_master.setChannelValue ( 5, 0 );
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
delay ( 500 );
dmx_master.setChannelValue ( 1, 0 );
dmx_master.setChannelValue ( 2, 0 );
dmx_master.setChannelValue ( 3, 0 );
dmx_master.setChannelValue ( 4, 250 );
dmx_master.setChannelValue ( 5, 0 );
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
delay ( 1000 );
}
else
{
// turn DMX off:
dmx_master.setChannelValue ( 1, 0 );
dmx_master.setChannelValue ( 2, 0);
dmx_master.setChannelValue ( 3, 0 );
dmx_master.setChannelValue ( 4, 0 );
dmx_master.setChannelValue ( 5, 0);
dmx_master.setChannelValue ( 6, 0 );
dmx_master.setChannelValue ( 7, 0 );
dmx_master.setChannelValue ( 8, 0 );
}
}
}