DMX512 ADDRESSING CHNAGE BY BUTTON

Hi !

I am using DMX512 with dmx library.

library is available here.

http://www.deskontrol.net/descargas/proyectos/arduino-four-universes-dmx-library/arduino-four-universes-dmx-library-0.3.zip

& Here is the code

#include <lib_dmx.h>  // comment/uncomment #define USE_UARTx in lib_dmx.h as needed

// This example receive 4 channels from address 1 to 4 and write analog values to PWM pins 2 to 5

// outputs update in main loop


//*********************************************************************************************************
//                        New DMX modes *** EXPERIMENTAL ***
//*********************************************************************************************************
#define    DMX512     (0)    // (250 kbaud - 2 to 512 channels) Standard USITT DMX-512
#define    DMX1024    (1)    // (500 kbaud - 2 to 1024 channels) Completely non standard - TESTED ok
#define    DMX2048    (2)    // (1000 kbaud - 2 to 2048 channels) called by manufacturers DMX1000K, DMX 4x or DMX 1M ???

void setup() 
{
  ArduinoDmx0.set_control_pin(22);    // Arduino output pin for MAX485 input/output control (connect to MAX485 pins 2-3) 
  ArduinoDmx0.set_rx_address(1);      // set rx0 dmx start address
  ArduinoDmx0.set_rx_channels(4);     // number of rx channels
  ArduinoDmx0.init_rx(DMX512);        // starts universe 0 as rx, NEW Parameter DMX mode
  
}  //end setup()

void loop()
{
  //write values from dmx channels 1-4 universe 0 to arduino pwm pins 2-5
  analogWrite(2, ArduinoDmx0.RxBuffer[0]);  //buffers 0 indexed
  analogWrite(3, ArduinoDmx0.RxBuffer[1]);
  analogWrite(4, ArduinoDmx0.RxBuffer[2]);
  analogWrite(5, ArduinoDmx0.RxBuffer[3]);
}  //end loop()

This code works perfect & receiving address is 1

I want to put one toggle button in loop when button is false then

receiving address is 1 & when button is true then receiving address is 5

How can i change this in loop?

Untested but something like this...

#include <lib_dmx.h>  // comment/uncomment #define USE_UARTx in lib_dmx.h as needed

// This example receive 4 channels from address 1 to 4 and write analog values to PWM pins 2 to 5

// outputs update in main loop


//*********************************************************************************************************
//                        New DMX modes *** EXPERIMENTAL ***
//*********************************************************************************************************
#define    DMX512     (0)    // (250 kbaud - 2 to 512 channels) Standard USITT DMX-512
#define    DMX1024    (1)    // (500 kbaud - 2 to 1024 channels) Completely non standard - TESTED ok
#define    DMX2048    (2)    // (1000 kbaud - 2 to 2048 channels) called by manufacturers DMX1000K, DMX 4x or DMX 1M ???

#define buttonPin 6   // Pin button is connected to (other side of button connects to GND)

void setup()
{
  pinMode(buttonPin,INPUT_PULLUP);
  ArduinoDmx0.set_control_pin(22);    // Arduino output pin for MAX485 input/output control (connect to MAX485 pins 2-3)
  ArduinoDmx0.set_rx_address(1);      // set rx0 dmx start address
  ArduinoDmx0.set_rx_channels(8);     // number of rx channels
  ArduinoDmx0.init_rx(DMX512);        // starts universe 0 as rx, NEW Parameter DMX mode
 
}  //end setup()

void loop()
{
  unsigned int baseChannel = 1;       // Assume button not pressed
  
  if (digitalRead(buttonPin) == LOW){
    baseChannel = 5;                  // Button pressed so alter base address
  }
  //write values from dmx channels 1-4 universe 0 to arduino pwm pins 2-5
  analogWrite(2, ArduinoDmx0.RxBuffer[baseChannel - 1]);  //buffers 0 indexed
  analogWrite(3, ArduinoDmx0.RxBuffer[baseChannel]);
  analogWrite(4, ArduinoDmx0.RxBuffer[baseChannel + 1]);
  analogWrite(5, ArduinoDmx0.RxBuffer[baseChannel + 2]);
}  //end loop()

Dear Sir,

Thanks for idea. I will test it. You have chnaged number of receiving channel 3 to 8 & change in loop

Is this possible to make like this.

boolean sw = false;

if (digitalRead(sw) == low){
ArduinoDmx0.set_rx_address(1);      // set rx0 dmx start address
}
else
{
ArduinoDmx0.set_rx_address(5);      // set rx0 dmx start address
}

I have to change something in loop.

Is above method is Ok

Roshani:
Dear Sir,

Thanks for idea. I will test it. You have chnaged number of receiving channel 3 to 8 & change in loop

Try your idea and see if it works.
As you have no DMX control over how many channels the desk sends then apart from the extra bytes for a bigger receive buffer it should not matter if you receive 4 or 8 bytes and select the 4 you want.