Master dimmer dmx channel code help

I have a fully functional and working programable dmx led strip fixture 4ch RGB and Strobe want to a master dimmer channel but every which way I try it either doesn't work at all or only works partly...any help or ideas would be great i've been searching the internet for days

Yeah, we get that a lot.

ok let me ask it more plainly because know what language to use to get to do what i want it to do i need to take percentage A and percentage B and combine them works fine on paper but coding it not so much sorry if i'm half an idiot at this but sure its something simple i'm just not seeing

Yeah, we get that a lot too.

(Hint: we can't see your code)

Won't let me post it yet because i'm new here or atleast posting here anyway I'll do it this way...

#include <DMXSerial.h>
#include <EEPROM.h>
#include <TM1637Display.h>

#define CLK 3
#define DIO 4
#define UP  7
#define DN  8



TM1637Display display(CLK, DIO);
long previousMillis = 0;
long interval = 8000;

int X = (EEPROM.read(0)+ EEPROM.read(1));
int pres = 0;


const uint8_t d[] = { SEG_B | SEG_C | SEG_D | SEG_E | SEG_G };

int ch = 4;
#define D DMXSerial.read(X+4)
#define R DMXSerial.read(X)
#define G DMXSerial.read(X+1)
#define B DMXSerial.read(X+2)
#define S DMXSerial.read(X+3)

void setup() {
  DMXSerial.init(DMXReceiver);
  display.setBrightness(6);
  pinMode (7,INPUT);
  pinMode (8,INPUT);
  pinMode (9,OUTPUT);
  pinMode (10,OUTPUT);
  pinMode (11,OUTPUT);
  
  display.clear();
  
  
}

void loop() {   
  
   if (S > 0)  {
        analogWrite (9, R);
        analogWrite (10,G);
        analogWrite (11,B);
        delay(285-S);
        analogWrite (9, 0);
        analogWrite (10,0);
        analogWrite (11,0);
        delay(285-S);
    } 
    else {
        analogWrite (9, R);
        analogWrite (10,G);
        analogWrite (11,B);
      }
           
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis > interval){ display.clear(); }

  else { display.setSegments(d,1,0);
         display.showNumberDec(X,false,3,1); }

  if (digitalRead(UP)==1) {
    if (pres==0){
      X++;
      pres=1;
      previousMillis = currentMillis;
      delay (100); }
    else { pres=0; }}
    
  if (digitalRead(DN)==1) {
    if (pres==0){
      X--;
      pres=1;
      previousMillis = currentMillis;
      delay (100); }
    else { pres=0; }}  

  if (X > 512-(ch)) {X=1;}
  if (X < 1) {X=512-(ch);}

  EEPROM.write(0,highByte(X));
  EEPROM.write(1,lowByte(X));

             
    }
  

I can't see anything that relates to percentage A or percentage B in that code.

The comments are a bit confusing too.

A one element array.
What's it for?

or lack of comments yeah let me fix that and come back with those and a better explanation of what I'm trying to do

Some longer variable names would be nice too - single character globals are so seventies :wink:

Yea, Seriously Bad Idea:

#define D DMXSerial.read(X+4)
#define R DMXSerial.read(X)
#define G DMXSerial.read(X+1)
#define B DMXSerial.read(X+2)
#define S DMXSerial.read(X+3)

I'm used to being the only one to my code and I type with 2 fingers but here it is again with explanations ... if you can get passed my simple and horrible attempt at coding but hey it all works so far just have this issue

#include <DMXSerial.h>
#include <EEPROM.h>
#include <TM1637Display.h>

#define CLK 3  //pin layout for TM1637
#define DIO 4
#define UP  7  //pin layout for DMX address adjustment
#define DN  8  



TM1637Display display(CLK, DIO);
long previousMillis = 0;
long interval = 8000;

int X = (EEPROM.read(0)+ EEPROM.read(1)); // get saved DMX address
int pres = 0;


const uint8_t d[] = { SEG_B | SEG_C | SEG_D | SEG_E | SEG_G };

int ch = 4;   // set number of DMX channels
                       
#define R DMXSerial.read(X)     // DMX channel 1 RED
#define G DMXSerial.read(X+1)   // DMX channel 2 GREEN
#define B DMXSerial.read(X+2)   // DMX channel 3 BLUE
#define S DMXSerial.read(X+3)   // DMX channel 4 STROBE
#define D DMXSerial.read(X+4)   // DMX channel 5 MASTER DIMMER

void setup() {
  DMXSerial.init(DMXReceiver);
  display.setBrightness(6);
  pinMode (7,INPUT);
  pinMode (8,INPUT);
  pinMode (9,OUTPUT);       // RED pin
  pinMode (10,OUTPUT);      // GREEN pin
  pinMode (11,OUTPUT);      // BLUE pin
  
  display.clear();
  
  
}

void loop() {   

  // Main funtion of RGB dimmers and STROBE
  
   if (S > 0)  {
        analogWrite (9, R);
        analogWrite (10,G);
        analogWrite (11,B);
        delay(285-S);
        analogWrite (9, 0);
        analogWrite (10,0);
        analogWrite (11,0);
        delay(285-S);
    } 
    else {
        analogWrite (9, R);
        analogWrite (10,G);
        analogWrite (11,B);
      }

// What I need to do here is get DMX channel 5 (D) to be a master dimmer eg. R is at 75%, G at 50% and B at 100% of the max 255 but D is only at 50% need  
// it to dim R,G,B proportially... the equation I have for each channel individually arduino doesn't like so i think I'm just not using the right language
//      (((((R/255)*100)-((D/255)*100))*255)/100) ---- Doesn't work does nothin on DMX that is where percentages come in 
//      R -(255-D)  ---- Kinda worked but only if channel was maxed out at 255
          
           // Display settings
           
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis > interval){ display.clear(); }

  else { display.setSegments(d,1,0);
         display.showNumberDec(X,false,3,1); }

  // DMX address adjustment
  
  if (digitalRead(UP)==1) {
    if (pres==0){
      X++;
      pres=1;
      previousMillis = currentMillis;
      delay (100); }
    else { pres=0; }}
    
  if (digitalRead(DN)==1) {
    if (pres==0){
      X--;
      pres=1;
      previousMillis = currentMillis;
      delay (100); }
    else { pres=0; }}  

  if (X > 512-(ch)) {X=1;}
  if (X < 1) {X=512-(ch);}

  // Save DMX address
  EEPROM.write(0,highByte(X));
  EEPROM.write(1,lowByte(X));

             
    }
  

that part is for led display for dmx address

It sounds like you need to calculate a value for the analogWrites in this fashion:

  unsigned int Red = R*D/255;

Edit: one int too many.

nope still does nothing when hooked up to dmx but atleast is a shorter way for me do the math

Post what you did.


unsigned int RED = R*D/255;

void setup() {
  DMXSerial.init(DMXReceiver);
  display.setBrightness(6);
  pinMode (7,INPUT);
  pinMode (8,INPUT);
  pinMode (9,OUTPUT);       // RED pin
  pinMode (10,OUTPUT);      // GREEN pin
  pinMode (11,OUTPUT);      // BLUE pin
  
  display.clear();
  
  }

void loop() {   

  // Main funtion of RGB dimmers and STROBE
  
   if (S > 0)  {
        analogWrite (9, RED);
        analogWrite (10,G);
        analogWrite (11,B);
        delay(285-S);
        analogWrite (9, 0);
        analogWrite (10,0);
        analogWrite (11,0);
        delay(285-S);
    } 
    else {
        analogWrite (9, RED);
        analogWrite (10,G);
        analogWrite (11,B);
      }

Move the new code for Red to the start of your loop function. As it is, you only calculate it once.

Thank you sooo much works perfect