Code for automatic blind doesnt work fine

Hello everybody, I have an electric blind in my house, but it only goes up or down if you keep pressing up or down buttons. So i decided to make a code with arduino in which if I press 2 times within half a second it goes up automatically, that code works fine. The problem is with the first part of the code wich purpose is that if i keep pressing the button it keeps going up or down without the “automatic” thing until I release the button.
Ive look everywhere the code and I dont know why the non automatic thing doesnt work.
Oh the out signal is working when is LOW, my relays are negative logic

const int I1=3; //UP button
const int I2=4; //DOWN button
const int O1=6; //UP contact
const int O2=8; //DOWN contact

  int button1=0;
  int button2=0;
  int actual1=0;
  int actual2=0;
  int last1=0;
  int last2=0;
  unsigned long t1=0; //timer for contact delay
  unsigned long t2=0;
  unsigned long tc=0; //timer for activation delay
  unsigned long tact=0;

void setup() {
  Serial.begin(9600);
  pinMode(I1, INPUT);  //In and OUTs
  pinMode(I2, INPUT);
  pinMode(O1, OUTPUT);
  pinMode(O2, OUTPUT);
}

void loop() {
  actual1=digitalRead(I1);   //Reading buttons
  actual2=digitalRead(I2);
   if (actual1 == HIGH)  //trying if the motor is working while the button is active
   {
    Serial.println(actual1); //the conditional works, but the motor doesnt activate
    digitalWrite(01, LOW);
    
    delay(50);
   }
   if (actual2 == HIGH)
   {
    Serial.println(actual2);
    digitalWrite(02, LOW);
    
    delay(50);
   }

  if (actual1 != last1) {    // if its true then the button was pushed and released
    if (actual1 == LOW) {         //if changed to LOW the button has been released
      button1++;
      if (button1==1) {         
        t1=millis();
        digitalWrite(O1, LOW); //Initialize the timer between pushes
      }
    }
    last1=actual1;
  }
  if (actual2 != last2) {     //The same for down
    if (actual2 == LOW) {
      button2++;
      if (button2==1) {
        t2=millis();
        digitalWrite(O2, LOW);
      }
    }
    last2=actual2;
  }
  if (button1 > 0) {               //We check if the button pushed 2 times and if the time between pushes is half a second or less
    if ((button1 == 2) && ((millis()-t1) <= 500 )) {
      digitalWrite(O1, LOW);                                  //activate and temporize
      tc=millis();
      tact=millis();
      while ((tact-tc)<=21000){         //while timer is active we only get out of it if any button is pressed
        tact=millis();
        if((digitalRead(I1)==HIGH) || (digitalRead(I2)==HIGH)){
          delay(50);
          actual1=LOW;
          actual2=LOW;
          button1=0;
          button2=0;
          tact=tc+30000;                //If any button is pressed we make the condition false
        }
      }
      digitalWrite(O1, HIGH);             //And turn off motor
      delay(300);
    }
    if ((millis()-t1)>500) {              //if time is greater than half a second we reset everything and turn of motor
      button1=0;
      digitalWrite(O1, HIGH);
    }
  }
  if (button2 > 0) {                           //the same for down
    if ((button2 == 2) && ((millis()-t2) <= 500 )) {
      digitalWrite(O2, LOW);
      tc=millis();
      tact=millis();
      while ((tact-tc)<=21000){
        tact=millis();
        if((digitalRead(I1)==HIGH) || (digitalRead(I2)==HIGH)){
          actual1=LOW;
          actual2=LOW;
          tact=tc+30000;
          button2=0;
          button1=0;
        }
      }
      digitalWrite(O2, HIGH);
      delay(300);
    }
    if ((millis()-t2)>500) {
      button2=0;
      digitalWrite(O2, HIGH);
    }
  }


}

If anyone can help please?

Window.ino (2.99 KB)

Your variable names are too cryptic. Why not use the names you give them in the comments? You are using 0 and 1 instead of true and false, which also tarnishes the readability. Then you perform arithmetic comparisons on them. Why? The design seems overly complex for such a simple task - usually a sign of no top down approach.

Look at the state change detection example. You want to make the blinds move when the switch BECOMES pressed, not when the switch IS pressed. Of course, you'll need some way of determining when to stop them, usually done using limit switches.

Yes you are right I put names to the variables that maybe are confusing, but I dont know how to do it simplier, its the simplest way i can imagine to do what i want.
Back into the code I just realize I made a mistake making digitalWrite(01... instead of O1, stupid mistake.
Thanks both of you anyway!
PaulS the limit switch is just a timer, because the blind has a limit switch itself, so if the time going up is greater it just will ignore that signal

PaulS the limit switch is just a timer, because the blind has a limit switch itself, so if the time going up is greater it just will ignore that signal

So, when the open switch BECOMES pressed, turn the open pin on, delay(), and turn the open pin off. When the close switch BECOMES pressed, turn the close pin on, delay(), and turn the close pin off.

Tripinbell:
Yes you are right I put names to the variables that maybe are confusing, but I dont know how to do it simplier, its the simplest way i can imagine to do what i want.
Back into the code I just realize I made a mistake making digitalWrite(01… instead of O1, stupid mistake.
Thanks both of you anyway!

That is an absolutely perfect example of why you should use meaningful variable names. You set yourself up for that failure by choosing that weird name. I told you before, you commented the variables when you created them. Look at the comments. Are you really trying to tell me you couldn’t make names out of them?

For example:

const int O2=8; //DOWN contact

how about:

const int downContact=8; //

PaulS:
So, when the open switch BECOMES pressed, turn the open pin on, delay(), and turn the open pin off. When the close switch BECOMES pressed, turn the close pin on, delay(), and turn the close pin off.

That is exactly what it does, but instead of delay i used millis in order to be able of "watching" if any button is pressed, coz that is a condition to stop.

aarg you are totally right, I used those names to be faster doing the code, but yes in the future i will use your way, the strange thing is that arduino compiler didnt detect the output wrong name
Thanks everyone! Now it works perfect

Now it works perfect

Have you given the variables meaningful names ?
Now improve it further by using byte variable instead of ints where the value is in the range 0 to 255.