Please help with Encoder and IR remote

hi guys,

I am back with new issues :slight_smile: and kindly asking for assistance.

So, i have a rotary encoder to control brightness of 7 seg displays, code below works as it should, i can control brightness from 0 to 15 and display value on display.

void encoder_brightness(){

  static int state=0,counter=15;

    state=(state<<1) | digitalRead(CLK_PIN) | 0xe000;

    if (state==0xf000){
       state=0x0000;
       if(digitalRead(DATA_PIN))
         counter--;
       else
         counter++;

       if (counter>15) {(counter = 15);}
       if (counter<0) {(counter = 0);}

       singlecounts = counter % 10;
       tensofcounts = counter / 10;

       display1.setBrightness(counter);
       display2.setBrightness(counter);
       display3.setBrightness(counter);
       display4.setBrightness(counter);
       display5.setBrightness(counter);
       display6.setBrightness(counter);
       display7.setBrightness(counter);

       MaximCC.setChar(0,7,tensofcounts,false);
       MaximCC.setChar(0,6,singlecounts,false);
       delay(0); 
    } 
}

Now, i would like to add option to control brightness with IR remote as well, so i’ve made a new loop for IR remote and it works ONLY if i make new value for brightness, ie. “IR_brightness…”

What i would like to do is, combine the two, so that i can control it with IR remote AND with encoder by using the same “counter” value and to display the value on screen. So if i adjust brightness on encoder to 10, then if i press the button on IR remote it would just pick up whatever the current value is…

code for IR remote is

if(results.value == IR_brightness_DOWN){
       IR_brightness--;
     }
     if (results.value == IR_brightness_UP){
       IR_brightness++;
     }

IR_brightness_DOWN and IR_brightness_UP are definitions of IR remote button hex code

I’ve tried everything to insert above code into main encoder loop but no go.

Any ideas would be appreciated.

many thanks,
Alek

elcrni:
I've tried everything to insert above code into main encoder loop but no go.

Any ideas would be appreciated.

Show your work.

@dougp

But that's the whole work i have :slight_smile:

I have one loop for encoder, it works. I make a new loop for IR remote for brightness, it works. I just need to combine the two... if possible

Thanks,
Alek