Blink without delay again :) But now with Dimmer ("just" count +1)

Dear Arduino Forum,

I have been trying for a few weeks now on my circuit for a staircase light. I would like to illuminate the individual steps one after the other (slowly dim up). I decided to switch via DMX, as there are CE-certified modules that can output the power to the individual LED strips and I dont have to get panic that I burn my house down.
I quickly realized that the circuit does not work with a delay and it is clear to me that I have to use the Blink without delay function. But that is going to be very complex. Actually I am already struggeling with the dimm up of the steps. I need a output a number between 1 and 255 (not PWM the Number). With the 2nd switch I am trying the same with a simpler way (just to try).
I think I only have some mistake with the set millis. It would be nice if somebody have a look at my project and can tell me if I am absolutely wron and I should buy 2 times the 350€ plugin-version.

Thanks Mathias

// DMX Bibliothek einfügen

#include <lib_dmx.h>

// Variablen deklarieren in denen die Startzeiten der einzelnen Zeitfunktionen gespeichert werden
unsigned long startzeit_CH_1 = 0;
unsigned long startzeit_CH_2 = 0;
unsigned long startzeit_CH_3 = 0;
unsigned long startzeit_CH_4 = 0;

// Definition DMX Modis

#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 ???

// Definition der DMX Ausgänge 

// Definition der Schalter

// Definitionen der einzelnen Zeiten um DMX +1 zu Dimmen

#define        Dimmzeit_CH_1   100UL
#define        Dimmzeit_CH_2   100UL
#define        Dimmzeit_CH_3   100UL
#define        Dimmzeit_CH_4   100UL


// Variable setzen für Helligkeit (initial 0)

int Helligkeit_CH_1 = 0;
int Helligkeit_CH_2 = 0;
int Helligkeit_CH_3 = 0;
int Helligkeit_CH_4 = 0;


// Pins als Ausgang
void setup() 
{
    // Pins 2 bis 13 as inputs mit pullup, (button pressed = 0, button free = 1) 
  for (int i=2;i<=13;i++) 
  {
    pinMode(i,INPUT);            // pins als inputs                                 
    digitalWrite(i, HIGH);       // Pullup                                 
  }
  
  ArduinoDmx0.set_tx_address(1);      // DMX start adresse                                      
  ArduinoDmx0.set_tx_channels(100);   // Anzahl DMX Kanäle                            
  ArduinoDmx0.init_tx(DMX512);        // StartUniverse als TX, standard mode DMX512                                      
}


void loop() {

if (digitalRead(2) == LOW) {                                                  //wenn Schalter 2 gedrückt
  if (millis - startzeit_CH_1 >= Dimmzeit_CH_1); startzeit_CH_1 = 1;{         //wenn Zeitabnehmer 1 über Dimmzeit 1 dann Helligkeit +1 und Startzeit 1
     for (Helligkeit_CH_1 <= 255; Helligkeit_CH_1 = Helligkeit_CH_1 +1;) {
    ArduinoDmx0.TxBuffer[0] = (digitalRead(2), Helligkeit_CH_1);
     }  
  }
}

if (digitalRead(2) == HIGH); {
    ArduinoDmx0.TxBuffer[0] = 0;
    Helligkeit_CH_1 = 0;
    startzeit_CH_1 = 0;


}
if (digitalRead(3) == LOW); {                                                   
     ArduinoDmx0.TxBuffer[1] = (digitalRead(3), startzeit_CH_2/Dimmzeit_CH_2);
     }

if (digitalRead(3) == HIGH); {
    ArduinoDmx0.TxBuffer[1] = 0;
    startzeit_CH_1 = 0;
}

}

What stuff, sensors etc. do You have to initiate the lighting up?
What’s the strategy?
What happens and what do want to happen? I don’t get that from Your posting.

Hi Railroader,

you`re right actually it is not to see.
I am still trying to build the program.
At the moment i want easily to Push a Button (digital Read2 or digitalread3), than (when I push) it should dimm up a LED (for that i have to send a number between 1 and 255 to ArduinoDmx0.TxBuffer[0]) . At the best way I start with 1 and give over a time (Dimmzeit_CH_1) +1 until I am at 255 and than it should stay at 255 until I let the button.
I know that i have at my staicase later a sensor whitch doesnt give me the whole time a HIGH or LOW but at my actuall project it is enough when I have the function - push the button > dimm up (over a time) and let the led burning until I dont push the Button anymore.

(the plan later is that i have a Photoelectric barrier when I cross that a timer starts for x seconds when the staircase light is on than the next step will be when the 1st step is on the 2nd step should dimm up x milliseconds later than the 1st and so on but thats my next step for me :wink:

Sorry for a so complicated explanation :wink:
But thanks for answearing

I recommend You to make a real light test of a LED strip to find out the PWM values that give useful light emission. 1 - 255 is math, playing with numbers. Just a guess to trigger You I say that values below 50 and values above 200 have no significance.
The time for starting the light up of the different LED strips should be based on measuring the time used for a normal walk in the stair way.
If You terminate the lights by a time out or a second button… up to You.
Do we get closer?

You´re right again.
1-255 is probably is not the perfect spectrum i have to work with (but I still have the problem that my “dimm up without delay” doesnt work). But it is enough for me that one step doesnt turn on directly full it should dimm up over 0,5 seconds (so the time i am between 1 and 50 and 200 and 255 is realy short)- the 2nd step is dimming up 0,3 (or so youre right I have to measure) seconds after the 1st step has begun)

if (millis - startzeit_CH_1 >= Dimmzeit_CH_1);

OOPS

if (digitalRead(2) == HIGH);

OOPS

And there’s more . . .

Okey. I think of this:
You initiate the sequence by, a button, detector, whatever…
In that moment You set time variables for starting each LED strip.
Each LED PWM starts from a value You have decided for, not 1, when the LED time for start is passed. Let’s say LED strip 1 now, LED strip2 5 seconds later etc. Set a flag for each LED that tells “activated” when millis() has exceeded each start time.
Also select a step up rate, how many milliseconds between stepping up providing that the flag for the strip is active.
Any help?

Yes I am an absolute beginner thats why I am asking here for help.
I am sure there some oops but I am trying and I am sure that I am on the right way since weeks :slight_smile:

There are a few helpful topics like “How to do several things at the same time”, “blink without delay”. Read them and check what You find.

You don’t place a

;

after if(blah blah blah)


BTW
In the Arduino IDE, use Ctrl T to format your sketches.

Thanks Railroader

Thanks that is usefull :wink:
but not the only problem in the sketch :wink:
I know it is here

if (digitalRead(2) == LOW) { //wenn Schalter 2 gedrückt
if (millis - startzeit_CH_1 >= Dimmzeit_CH_1); startzeit_CH_1 = millis ; { //wenn Zeitabnehmer 1 über Dimmzeit 1 dann Helligkeit +1 und Startzeit 1
for (Helligkeit_CH_1 <= 255; Helligkeit_CH_1 = Helligkeit_CH_1 + 1;) {
ArduinoDmx0.TxBuffer[0] = (digitalRead(2), Helligkeit_CH_1);
}
}
}

if (digitalRead(2) == HIGH) {
ArduinoDmx0.TxBuffer[0] = 0;
Helligkeit_CH_1 = 0;
startzeit_CH_1 = 0;
}

That is what I tried to write

;


Follow this format:

if(blah == blah blah)
{
        //do something
}

I did not read Your existing code. To do that I ask You for a flow chart telling the flow of the logic.
I have plenty of projects, electronical as well as mechanical and the time I offer You is not unlimited. Analyzing Your code is beyond what I offer.

Hi Railroader,

I highly appreciate your work but actually my focus is to get the easyest 1st step (oviously not for me). I already tried my project ESPeasy and wastest so much time until I found out that it is not possible to dim up over such a short time over DMX so actually I am interested about the basic is it possible (and how) to dimm a LED quickly up (over 0,5 - 1 sek) over DMX or do I have to change to somethink else.

Thanks

Dimming using a step rate that make it happen during 0,5 - 1 second is no problem.
However, the DMX world is unknown to me.

This

1;) {

in the for loop has a missing part, the part that is performed at the end of each trip through the loop. It’s where anything that would make the loop ever stop is meant to be changed. With nothing there, nothing changes, your loop runs forever and… well, whatever it does is not what you want.

    for (i = 0; i < 10; i++) {
        Serial.println(i);
    }

The i++ increments i, so when it becomes >= 10 the loop is done.

I think there may be other basic syntax errors. Using auto-format can point up some of these; setting the compiler verbosity to the maximum may generate warnings, but C/C++ will happliy let you make this kind of mistake, because, well, sometimes it’s what is desired and is legal.

So not strictly syntax errors as such, just a basic misunderstanding of the syntax and how it can srsly bite you on a fleshy part of your body.

The for loop in you setup(0) is the right pattern.

a7