if else priority

Is there a way to set priority with an if else statement?

I’m trying to do following using the Conceptinetics library:

I’m working on some preset buttons for light scenes. The only thing is, if 2 or more presets holds the same dmx channels it doesnt work.

For example, in preset 1 and 2 it will switch dmx channels 1/4 to 255. If preset 1 is HIGH en preset 2 is LOW the lights will flicker since both presets the LOW state should turn the lights of.

So i’m wondering if i can give a high priority to a HIGH status in the if else state…

code:

#include <Conceptinetics.h>

#define DMX_MASTER_CHANNELS 512

#define RXEN_PIN 2

DMX_Master dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );

int zaallicht = 8;
int werklicht = 9;
int doei = 7;

// the setup routine runs once when you press reset:
void setup() {

pinMode (zaallicht, INPUT_PULLUP);
pinMode (werklicht, INPUT_PULLUP);
pinMode (doei, INPUT_PULLUP);

// Enable DMX master interface and start transmitting
dmx_master.enable ();

}

// the loop routine runs over and over again forever:
void loop()
{

int zaallicht = digitalRead(8);

if (zaallicht == LOW) {

dmx_master.setChannelRange ( 256, 270, 128 );}

else {

dmx_master.setChannelRange ( 256, 270, 0 );}

int werklicht = digitalRead(9);

if (werklicht == LOW) {

dmx_master.setChannelRange (256, 266, 128);
dmx_master.setChannelRange (73, 78, 255);
dmx_master.setChannelValue (10, 200);
dmx_master.setChannelValue (15, 200);
dmx_master.setChannelValue (6, 100);
dmx_master.setChannelValue (9, 100);
dmx_master.setChannelValue (16, 100);
dmx_master.setChannelValue (19, 100);
dmx_master.setChannelValue (35, 150);
dmx_master.setChannelValue (38, 150);
}

else {

dmx_master.setChannelRange (256, 266, 0);
dmx_master.setChannelRange (73, 78, 0);
dmx_master.setChannelValue (10, 0);
dmx_master.setChannelValue (15, 0);
dmx_master.setChannelValue (6, 0);
dmx_master.setChannelValue (9, 0);
dmx_master.setChannelValue (16, 0);
dmx_master.setChannelValue (19, 0);
dmx_master.setChannelValue (35, 0);
dmx_master.setChannelValue (38, 0);}
}

Please have a look at How to use the forum on howto post your code. Because cool code 8)

next, priority is simply done by what is matched first. So top to bottom.

Before posting code again, put EVERY } on a line BY ITSELF. Put EVERY { on a line BY ITSELF.

There is no excuse for jamming the } up against the end of the last statement in the block, making it difficult to see the program structure.

Use Tools + Auto Format to properly indent the code, then post it PROPERLY.

Execution of statements is fixed and sequential, there is no concept of priority.
If A is more important than B, test A first (outermost).

So thanks for all the comments, hereby the code again:

#include <Conceptinetics.h>

#define DMX_MASTER_CHANNELS 512

#define RXEN_PIN 2

DMX_Master dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );

int zaallicht = 8;
int werklicht = 9;

// the setup routine runs once when you press reset:
void setup() {

pinMode (zaallicht, INPUT_PULLUP);
pinMode (werklicht, INPUT_PULLUP);

// Enable DMX master interface and start transmitting
dmx_master.enable ();

}

// the loop routine runs over and over again forever:
void loop()
{

int zaallicht = digitalRead(8);

if (zaallicht == LOW) {

dmx_master.setChannelRange ( 256, 270, 128 );
}

else {

dmx_master.setChannelRange ( 267, 270, 0 );
}

int werklicht = digitalRead(9);

if (werklicht == LOW) {

dmx_master.setChannelRange (256, 266, 128);
dmx_master.setChannelRange (73, 78, 255);
dmx_master.setChannelValue (10, 200);
dmx_master.setChannelValue (15, 200);
dmx_master.setChannelValue (6, 100);
dmx_master.setChannelValue (9, 100);
dmx_master.setChannelValue (16, 100);
dmx_master.setChannelValue (19, 100);
dmx_master.setChannelValue (35, 150);
dmx_master.setChannelValue (38, 150);
}

else {

dmx_master.setChannelRange (256, 266, 0);
dmx_master.setChannelRange (73, 78, 0);
dmx_master.setChannelValue (10, 0);
dmx_master.setChannelValue (15, 0);
dmx_master.setChannelValue (6, 0);
dmx_master.setChannelValue (9, 0);
dmx_master.setChannelValue (16, 0);
dmx_master.setChannelValue (19, 0);
dmx_master.setChannelValue (35, 0);
dmx_master.setChannelValue (38, 0);
}
}

hereby the code again:

Yet again no code tags and not Auto Formatted

Last post i did was made by arduino itself through the tools menu…
I simply copied the tekst en posted in here…

arduino says there is no need to change the code for automatic format.

but maybe there is another way to give a state a priority…?

For example, if button A is pressed it should get a high priority… Resulting in outputting a DMX value.

but maybe there is another way to give a state a priority...?

For example, if button A is pressed it should get a high priority.. Resulting in outputting a DMX value.

You assign priority by putting the most important code first.

void loop()
{
   if(switchAPressed())
   {
      // What happens here is MORE important than what happens if switch B is pressed
   }
   else if(switchBPressed())
   {
      // Less important that if switch A is pressed
   }
}

debaggerboot:
Last post i did was made by arduino itself through the tools menu...

BS (unless maybe if you use an antient version). Otherwise if you select Copy for Forum it looks like

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

debaggerboot:
I simply copied the tekst en posted in here..

That's something different. And if you would actually READ How to use the forum you would see that's not appreciated!

debaggerboot:
arduino says there is no need to change the code for automatic format.

Arduino doesn't care jack! People who have to read it do. Just do the damn auto format and see how it cleares stuff up.

debaggerboot:
but maybe there is another way to give a state a priority...?

You writing complicated software for it. By default, no.

debaggerboot:
For example, if button A is pressed it should get a high priority.. Resulting in outputting a DMX value.

Then read button A first!