Console DMX Arduino

Émetteur DMX adressable

Matériel

  • ARDUINO Nano (microcontroleur)

  • potentiomètres

  • MAX RS485 (out DMX XLR-3)

  • Embase XLR Type D

  • Dip Switch

Code ARDUINO
console5knob003-ok.ino

.in,o#include <DMXSerial.h>


int DMX_adress ;


unsigned short dmxVal;


// the setup routine runs once when you press reset:

void setup() {


pinMode(2, INPUT_PULLUP); // pushbutton

pinMode(3, INPUT_PULLUP); // 1 dip-switch

pinMode(4, INPUT_PULLUP); // 2 dip-switch

pinMode(5, INPUT_PULLUP); // 4 dip-switch

pinMode(6, INPUT_PULLUP); // 8 dip-switch

pinMode(7, INPUT_PULLUP); // 16 dip-switch

pinMode(8, INPUT_PULLUP); // 32 dip-switch

pinMode(9, INPUT_PULLUP); // 64 dip-switch

pinMode(10, INPUT_PULLUP); // 128 dip-switch

pinMode(11, INPUT_PULLUP); // 256 dip-switch

pinMode(12, INPUT_PULLUP); // dip-switch 10 <=> TOOGLE sens de rotation

// initialize serial communication at 9600 bits per second:

//Serial.begin(9600);

//OU

// set as DMX output

DMXSerial.init(DMXController);


// config du SET-ZERO commme un interrupt

//attachInterrupt(digitalPinToInterrupt(2), interrrrupt, CHANGE );




}


// the loop routine runs over and over again forever:

void loop() {

DMX_adress = readDipSwitches();


if(DMX_adress == 0) {send_dmx_zero();}

else {readknob();}

if(digitalRead(12) == LOW) { send_dmx(5,0);} // DIP10

else { send_dmx(5,100); }

if(digitalRead(2) == LOW) { send_dmx(5,150);} // button

//DMXSerial.write(3, voltage);

delay(20); // wait a little bit

}



short readDipSwitches() {

dmxVal = 0;

if(digitalRead(3) == LOW) dmxVal += 1;

if(digitalRead(4) == LOW) dmxVal += 2;

if(digitalRead(5) == LOW) dmxVal += 4;

if(digitalRead(6) == LOW) dmxVal += 8;

if(digitalRead(7) == LOW) dmxVal += 16;

if(digitalRead(8) == LOW) dmxVal += 32;

if(digitalRead(9) == LOW) dmxVal += 64;

if(digitalRead(10) == LOW) dmxVal += 128;

if(digitalRead(11) == LOW) dmxVal += 256;

return dmxVal;

}



void readknob() {

long channel_1 = analogRead(A0);

send_dmx(0 ,channel_1 * 255 / 1020);

long channel_2 = analogRead(A1);

send_dmx(1 ,abs((channel_2 * 255 / 1020)-255));

long channel_3 = analogRead(A2);

send_dmx(2 ,(channel_3 * 255 / 1022));

long channel_4 = analogRead(A3);

send_dmx(3 ,abs((channel_4 * 256 / 1024)-255));

long channel_5 = analogRead(A4);

send_dmx(4 ,abs((channel_5 * 255 / 1020)-255));

}



//void interrrrupt(){

// while (digitalRead(2) == LOW){

// send_dmx(5,150);

// }

//}



void send_dmx(int adress, byte value){

//Serial.print("adress=");

//Serial.print(DMX_adress+adress);

//Serial.print(" value=");

//Serial.println(value);

DMXSerial.write(DMX_adress + adress, value);

}


void send_dmx_zero(){

for (int i = 1; i <= 512; i++) {

DMXSerial.write(i,0);

}

}