Dimming light using DMX

Hey guys, Im fairly new to Arduino and it would be great if someone could look over the code from our project.
The goal is to use two IR sensors, one to control the frequencies of a speaker and one to dim the brightness of a light. It all worked fine when we sticked to a simple LED, but as soon as we had to put the DMX shield and include the DMX simple code, we did not manage to make both sensors work. However, after some trying, we can now use one IR sensor and one potentiometer (to dim the light). The problem is, that the light does not fade gradually, but adapt 2-3 different stages of brightness. The LED still fades gradually though.
Do you have any idea, why two IR sensors dont work with the DMX shield and why the big light does not fade gradually? Heres our code so far.
Thanks a lot!

#include <DmxSimple.h>

//arduino: short leg of LED goes to ground;
//resistor necessary!
//PIN nr 9 goes to LED;
//if add potentiometer: 2 goes to A5, 1 goes to power, 5 Volts, 3 goes to ground
// if add distance sensor: (different color variations as frequency distance sensor)
// red goes to Data (a5);black to ground and yellow to power
//both distance sensors work without the DMX shield. The LED brightness can be dimmed and the frequencies for the speaker controlled
//testing by using potentiometer instead of one sensor

//INCLUSION OF DMX ==> distance sensor + potentiometer works, two distance sensors dont
//potentiometer does not dimm the bright light gradually, it seems to go in 3 steps and does not go from bright do dark, but randomly changes between the steps(furthermore there is a bit of noise so it sometimes changes without moving the potentiometer)
//However, the LED still fades gradually, has a smaller range though.

int ledPin = 9;
int ledValue = 0;
int sensor2Pin = A5; //light brightness
int sensor2Value = 0;
int sliderPin = A0; //speaker
int sliderValue = 0;
int toneValue = 0;

void setup() {
  // put your setup code here, to run once:
  // initialize serial communications at 9600 bps:
  //Serial.begin(9600);
  DmxSimple.usePin(3);
  //initialize serial communications for led brightness:
  Serial.begin(9600);


}

void loop() {
  // put your main code here, to run repeatedly:

  sliderValue = analogRead(sliderPin);
  toneValue = map(sliderValue, 0, 1023, 100, 10);
  tone(8, toneValue);
  // print out the value you read:
  Serial.println(toneValue);
  Serial.print("\t");
  delay(1);

  sensor2Value = analogRead (sensor2Pin); //second sensor, connect to led
  ledValue = map (sensor2Value, 0, 1023, 0, 255);
  analogWrite (ledPin, ledValue);
  Serial.print("\t");
  Serial.println(ledValue);

  DmxSimple.write(1, sliderValue ); //sliderValue/4 changes a little bit the sensitivity of the potentiometer input
  //DmxSimple.write(1 + 1, sliderValue ); 
  //+1? one for bright light, one for LED? not solved
  //39 refers to the channels (1-512) changing the channels does affect the light patterns and intensity
}
  sensor2Value = analogRead (sensor2Pin); //second sensor, connect to led

I am NOT going to go back and see what is connected to the pin whose number is stored in the sensor2Pin variable. That is a stupid name for the pin number variable. Use a name that does NOT require that I scroll back and re-read the comments to determine what this code is supposed to do.

Hello,

Correct me if I am wrong but:

44Hz is refresh frequency of DMX, it means that in 1sec, only 44 DMX values are sent through leds.
So if you want in 1 sec to set the brightness from 0 to 255 (0, 1, 2, 3.....) the 44Hz DMX spec would escape some values for your fade in/out effect.
So if you want to aim 256 values in a fade effect, it would last 6sec (44*6 = 264 > 256)

44Hz is refresh frequency of DMX, it means that in 1sec, only 44 DMX values are sent through leds.

its 44hz for all 512 channels so its takes 22.7mS to send a Full packet.

Do you have any idea, why two IR sensors dont work with the DMX shield and why the big light does not fade gradually? Heres our code so far.

i dont see anything on the code about IR.

but still.
DMX simple if i’m correct uses a ISR, same goes for the Tone function. this can mass stuff up.
also DONT! use Serial. dmx uses the RX and TX pin from the arduino.

gregy:
44Hz is refresh frequency of DMX, it means that in 1sec, only 44 DMX values are sent through leds.
So if you want in 1 sec to set the brightness from 0 to 255 ...
So if you want to aim 256 values in a fade effect, it would last 6sec (44*6 = 264 > 256)

This is not correct. I have not seen that kind of delay when I used DMX. And while there is a noticeable delay to sending the entire "universe" of 256 DMX channels, it is also common for a fade to only get some of those values. So, if the fade should occur over 1 second, that channel would only get perhaps the values 42,84,168,210, 252, 255. Another feature in many dimmers is that if they get two different values in the data stream in series (perhaps other than 0, and then 250) they assume it is to be a smooth fade, and smooth out the fade themselves, without getting explicit values for each step.

For your problems, I don't think it is because of the nature of DMX. Something is perhaps causing your system to send out the DMX universe only periodically.

I am not familiar with your DMX shield. But, some DMX interfaces do more than convert a data stream from the Arduino. Some have microprocessors and will continuously repeat the entire DMX universe until it is instructed the change something. This can greatly off-load the main processor.

I will also mention that you don't have to send out the entire DMX universe. You have to start with channel #1, I think, but you can stop any time you want. So, if you are OK with limiting yourself to the 1st 128 channels (or whatever quantity) , that can both quicken how fast your send a set of channels, and off load your processor to some extent, if the DMX interface is not automatically repeating the channel data.

-Joe