dmx strobe and master

hi all,
I’m still very new to Arduino so i am hoping you can help me.
i’ve been trying to make a dmx controlled light. and it works with dimming the led’s, only i am trying to implement a master and a strobe. and i cant figure out how.
hopefully you can help me

i am using the arduino nano.
this is the code i’m using

#include <DMXSerial.h> 

const int RedPin = 3;
const int GreenPin = 5;
const int BluePin = 6;

const int Input1 = 10;
const int Input2 = 11;
const int Input3 = 12;
const int Input4 = 13;
const int Input5 = A0;
const int Input6 = A1;
const int Input7 = A2;
const int Input8 = A3;
const int Input9 = A4;
const int Input10 = A5;

int Dip1 = 0;
int Dip2 = 0;
int Dip3 = 0;
int Dip4 = 0;
int Dip5 = 0;
int Dip6 = 0;
int Dip7 = 0;
int Dip8 = 0;
int Dip9 = 0;
int Dip10 = 0;

int startAddress = 1;


void setup () {
  DMXSerial.init(DMXReceiver);

  pinMode(RedPin, OUTPUT);
  pinMode(GreenPin, OUTPUT);
  pinMode(BluePin, OUTPUT);

  pinMode(Input1, INPUT);
  pinMode(Input2, INPUT);
  pinMode(Input3, INPUT);
  pinMode(Input4, INPUT);
  pinMode(Input5, INPUT);
  pinMode(Input6, INPUT);
  pinMode(Input7, INPUT);
  pinMode(Input8, INPUT);
  pinMode(Input9, INPUT);
  pinMode(Input10, INPUT);
}

  void loop () {

    if (digitalRead(Input1) == HIGH) {
      Dip1 = 1;
    }
    if (digitalRead(Input1) == LOW)  {
      Dip1 = 0;
    }
    
    if (digitalRead(Input2) == HIGH) {
      Dip2 = 2;
    }
    if (digitalRead(Input2) == LOW)  {
      Dip2 = 0;
    }
    
    if (digitalRead(Input3) == HIGH) {
      Dip3 = 4;
    }
    if (digitalRead(Input3) == LOW)  {
      Dip3 = 0;
    }
    
    if (digitalRead(Input4) == HIGH) {
      Dip4 = 8;
    }
    if (digitalRead(Input4) == LOW)  {
      Dip4 = 0;
    }
    
    if (digitalRead(Input5) == HIGH) {
      Dip5 = 16;
    }
    if (digitalRead(Input5) == LOW)  {
      Dip5 = 0;
    }

    if (digitalRead(Input6) == HIGH) {
      Dip6 = 32;
    }
    if (digitalRead(Input6) == LOW)  {
      Dip6 = 0;
    }

    if (digitalRead(Input7) == HIGH) {
      Dip7 = 64;
    }
    if (digitalRead(Input7) == LOW)  {
      Dip7 = 0;
    }

    if (digitalRead(Input8) == HIGH) {
      Dip8 = 128;
    }
    if (digitalRead(Input8) == LOW)  {
      Dip8 = 0;
    }

    if (digitalRead(Input9) == HIGH) {
      Dip9 = 256;
    }
    if (digitalRead(Input9) == LOW)  {
      Dip9 = 0;
    }

    if (digitalRead(Input10) == HIGH) {
      Dip10 = 512;
    }
    if (digitalRead(Input10) == LOW)  {
      Dip10 = 0;
    }


    startAddress = Dip1 + Dip2 + Dip3 + Dip4 + Dip5 + Dip6 + Dip7 + Dip8 + Dip9 + Dip10;
     if (startAddress == 0) {
    startAddress = 1;
  } 
     if (startAddress > 512) {
    startAddress = 512;
  }

    int MasterChannel = DMXSerial.read(startAddress);
    
    int RedChannel = DMXSerial.read(startAddress + 1);
    
    int GreenChannel = DMXSerial.read(startAddress + 2); 
    
    int BlueChannel = DMXSerial.read(startAddress + 3);

    int StrobeChannel = DMXSerial.read(startAddress + 4);
  

      analogWrite(RedPin, RedChannel);

      analogWrite(BluePin, BlueChannel);

      analogWrite(GreenPin, GreenChannel);

    }

Thanks in advance.

We can certainly help you to write that code better, and much, much shorter, if you would like.

For the master channel to control overall brightness, you can simply use

      analogWrite(RedPin, RedChannel*MasterChannel/255);

      analogWrite(BluePin, BlueChannel*MasterChannel/255);

      analogWrite(GreenPin, GreenChannel*MasterChannel/255);

What range of flashing rates is required?

Hi thank you.
The master works great. And for the strobe I wanted a rate from 0 to 20 hz. If that is possible.

Ok, great. I gave you the answer for the master channel, let's work together on the strobe.

Have a look at the example sketch "blink without delay". This will show you how to flash a led without using the delay() function. You cannot use delay() because it would prevent the Arduino from reacting to changes sent by the dmx controller.

In that sketch, you will see a period defined in milliseconds, so you will need to calculate the period you want for a given strobe rate. For example, if the required strobe rate was 5Hz, what period in ms would be needed between the led switching on or off?

hi i am having a little trouble implementing it in the code. so far i calculated the interval should be 50ms but i cant figure out how to implement it to the code.

soepvlees:
the interval should be 50ms

Not quite right. How did you get that figure? Let's see the code you wrote for that.

Well for it to change 20 times per second I divided 1000ms by 20. And outcomes 50ms.
And I didn't write any code I tried to implement the blink no delay function.

I asked about 5Hz, not 20Hz. But let's go with your example. 50ms is the period between the led switching from off to on and the next time it switches from off to on. But what is time time between switching off to on until it switches on to off?

I want it to turn on at 0ms then off at 50ms and back on at 100ms and off at 150ms ect.

I understood you wanted to use 20Hz as the example? Your answer above would be correct for 10Hz.

Oh right so it should be 25ms between updates.
How should I implement it to the code?

For your next step, I suggest writing a few lines of code to take the value from the strobe channel and calculate the period. To test that it is working I would normally suggest printing the result to Serial Monitor. Is that possible with your circuit?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.