oF - ARDUINO communication

Hi everyone!

I have an application with three buttons made using openFrameworks that selects a sequence in the arduino to be run, whenever any of the buttons is selected it sets a variable (b1Push, b2Push or b3Push) then a message is sent to the ARDUINO:

This is written in the update() function

        if (b1Push){
            prog=1;
        }

        if (b2Push){
            prog=2;
        }
        
        if (b3Push){
            prog=3;
        }
        
    
        arduinoCom.writeByte(prog);

it is running at 9600 bps

on the other hand I have the ARDUINO receiving that message, also at 9600 bps, it compares the button that was pushed before and the sequence that it activates (eg. if button 1 was pushed before, activo = 1) with the new message received (programa), if activo = programa, it does nothing and continues to run the code where interrupcion() was called. if activo != programa, then it resets the arduino and does the new sequence:

void interrupcion(){
  programa = Serial.read();
  if(programa != activo){
      resetFunc();  //call reset
  }
}

the problem I have is that when a sequence is running, and I push a button in my oF application, it takes at least 5 cycles in the Arduino before it receive what oF is sending, I think that they are not synchronized and when oF is “talking” Arduino is not listening, and when Arduino is listening, oF is not talking, eventually, they will synchronize (x number of cycles after I pushed the button) and the sequence activates,

How can I solve this problem? if that’s not the problem, then what is it?

THANK YOU! and sorry if any of my english is wrong… not a native!

(deleted)