help with windows electric shouters code

Hello!I want to control the electric shouters not only locally but also with the use of a master(2 push buttons) which will be near to the central door (for example if i want to go out i can close all the shouters from the master). I totally have 8 electric rollers(220v) .I found a code and i made a little modification.So,when i push the buttonUp the led1Up (motor for up) works correctly with a delay of 5 sec while if i push the buttonDown it does not work until the 5 sec pass.The opposite process is the same for buttonDown.

What i want to do is to have 2 choices :
1)To wait until the 5 sec pass so the shouters are up or down (This is the code which works now).

to stop with the buttons the shouters before the 5 sec expires(for example if the shouters are in the middle i want to stop them before the five sec) [code][code][code][/code][/code][/code]

int led1Up = 2;
int led2Down = 3;
int buttonUp = 4;
int buttonDown = 6;
void setup()
{
  pinMode(push1, INPUT_PULLUP);
  pinMode(led1, OUTPUT);
   pinMode(push2, INPUT_PULLUP);
  pinMode(led2, OUTPUT);
  
}

long off1 = 0;
long off2 = 0;

void loop()
{
  if( (digitalRead(led1Up) == LOW )&&(digitalRead(led2Down) == LOW )  && (digitalRead(buttonUp) == 

LOW)&& (digitalRead(buttonDown) == HIGH) ) 
  {
    digitalWrite(led1, HIGH);

   
    off1 = millis() + 5000; //store var of now + 5 seconds
    
  }
 
  if(digitalRead(led1) == HIGH    ) //if led is on
   
       
      if(millis() >= off1 ) //see if it's time to turn off LED
      {
         digitalWrite(led1Up, LOW); //it's time. this also re-enables the button
          
      }


if( (digitalRead(led2Down) == LOW )&&(digitalRead(led1Up) == LOW ) && (digitalRead(buttonDown) == LOW) && (digitalRead(buttonUp) == HIGH) ) //if LED is off  and button is pressed [low because it has pullup resistor]
  {
    digitalWrite(led2Down, HIGH);

   
    off2 = millis() + 5000; //store var of now + 5 seconds
   
  }
 
  if(digitalRead(led2Down) == HIGH) 
  
      if(millis() >= off2) 
      {
         digitalWrite(led2Down, LOW); 
       
      }    
  }

_2_BUTTONS_TIMER2VERSION.ino (1.35 KB)

I guess you mean motorised window blinds or shutters. I find your description difficult to follow.

Normally these have a control panel with 2 buttons marked up and down.
A long push (maybe this is your 5 seconds) sends the blinds to the end (either fully up or fully down depending on which button was pressed), continuing even after the button is no longer pressed.
A short push simply stops the blinds, if these are currently moving, then moves them only as long as the button is held, in the direction of the button. If held for longer that 5 seconds, again this is treated as a long push.

How does your scheme differ from this, if at all ?

Thanks for answering.To be more specific,in the existing code if i push the button up then the led( or motor) turns on for 5 sec.If i push the same button again before the expire of 5 sec,it does not stop.So i want to have the posibility to stop it before the expire of 5 sec.What code should i include in this sketch?

I want either to wait until the 5 sec expire or to push the button again before the end of 5 sec (so the shouters stay in a specific point).

The code is not mine(i am not very good with coding), and i try to put the extra code which i want)

Code aside, I would think that you need limit a limit switch (or switches) so that the motor stops on its own when it reaches the extremes of its travel limit. This should happen regardless of what button you’re pressing or not pressing.

If you want a button press to cancel an active press of the same button, you could do something like this:

instead of this:

if(millis() >= off1 ) //see if it's time to turn off LED

do this

if(millis() >= off1 ||  digitalRead(buttonUp) == LOW  ) //see if it's time to turn off LED

You have couple of problems, though:

  1. You have no button debounce or status change check which might cause the new code to be immediately executed because the user may not be able to release the button quickly enoough.

You could get away with either adding a short delay, say 250mS, after setting led1 to HIGH or doing something like this (but see point 2 below):

if(millis() >= off1 ||  ( digitalRead(buttonUp) == LOW  && off1 - millis() > 250 && off1 - millis() < 5000 )  ) //see if it's time to turn off LED
  1. Your use of millis() does not handle the situation approaching the millis() rollover so is not usual way of writing such code. Better is to set the time of the button press, not to calculate the expiry time in advance. So your test would be something like:
if ( millis() - buttonPressedAt > 5000 )  // button press expired

odi:
to stop with the buttons the shouters before the 5 sec expires(for example if the shouters are in the middle i want to stop them before the five sec)

you should look into a State Machine approach.

It is a little above your current coding, but learning this is essential.

Also, find a button press library and make it easier on yourself.

here is what I use for buttons and includes the ability to use single, double, triple and long presses.

#include "SimplePress.h"

const byte buttonPin0 = 2;
const byte buttonPin1 = 3;
const byte buttonPin2 = 4;

SimplePress button0(buttonPin0, 500);         // half second capture for multi-presses; uses default 200ms debounce
                                              // a long press is defined as greater than the capture time (500ms in this example)
                                              // or...
SimplePress button1(buttonPin1, 500, 150);    // or specify custom debounce time in ms

SimplePress button2(buttonPin2, 500);

void setup() 
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  button0.begin();
  button1.begin();
  button2.begin();
}

void loop() 
{
  if(int pressCount = button0.pressed())  // check to see if there is a button press event
  {
    switch(pressCount)  // the event can be any positive integer (the number of button presses) or -1 in the case of a long press
    {
      case -1:
        Serial.println(F("Button 0 long Press"));
        longFlashPin13();
        break;
      case 1:
        Serial.println(F("Button 0 one Press"));
        flashPin13(1);
        break;
      case 2:
        Serial.println(F("Button 0 two Presses"));
        flashPin13(2);
        break;
    }
  }
  if(int press2count = button1.pressed())
  {
    switch(press2count)
    {
      case -1:
        Serial.println(F("Button 1 long Press"));
        break;
      case 1:
        Serial.println(F("Button 1 one Press"));
        break;
    }
  }
  if (button2.pressed()) // Simple press detection
  {
    Serial.println(F("Button 2 Pressed!")); 
  }
}

void flashPin13(byte numTimes)
{
  for(byte i = 0; i < numTimes; i++)
  {
    digitalWrite(13, HIGH);
    delay(250);
    digitalWrite(13, LOW);
    if (i < numTimes - 1) delay(250);
  }
}

void longFlashPin13(void)
{
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
}

header file:

#ifndef SIMPLEPRESS_H
#define SIMPLEPRESS_H

#include <Arduino.h>

class SimplePress{
  public:
    SimplePress(int _pin, uint32_t _pressInterval, uint32_t _debouncePeriod = 200);
    bool begin();
    int8_t pressed();

  private:
    byte pressCount;
    byte lastState;
    byte pin;
    uint32_t lastMillis;
    uint32_t debouncePeriod;
    uint32_t pressInterval;
};

SimplePress::SimplePress(int _pin, uint32_t _pressInterval, uint32_t _debouncePeriod)
{
  pin = _pin;
  debouncePeriod = _debouncePeriod;
  pressInterval = _pressInterval;
}

bool SimplePress::begin()
{
  pinMode(pin, INPUT_PULLUP);
  lastState = HIGH;
  return true;
}

int8_t SimplePress::pressed()
{
  byte nowState = digitalRead(pin);
  if(nowState != lastState)
  {
    if(millis() - lastMillis < debouncePeriod) return 0;
    if(nowState == LOW)
    {
      lastMillis = millis();
      pressCount++;
    }
    else 
    {
      if (millis() - lastMillis > pressInterval) // a long press
      {
        lastState = nowState;
        pressCount = 0;
        return -1;
      }
    }
  }
  if(pressCount != 0)
  {
    if(millis() - lastMillis > pressInterval and nowState == HIGH)
    {
      int presses = pressCount;
      pressCount = 0;
      return presses;
    }
  }
  lastState = nowState;
  return 0;
}

#endif

6v6gt:
I guess you mean motorised window blinds or shutters.

Oh. I thought he was talking about a car alarm.

Thanks for your help everybody. 6v6gt i tryied the : if(millis() >= off1 || digitalRead(buttonUp) == LOW ) and as you said there are problems with the buttons then i put the other code as below but when i push the button after the first push,it doesn't turn off the led1Up.
I am a little confused(to be specific a lot of confused).

int led1Up = 2;
int led2Down = 3;
int buttonUp = 4;
int buttonDown = 6;
void setup()
{
  pinMode(buttonUp, INPUT_PULLUP);
  pinMode(led1Up, OUTPUT);
   pinMode(buttonDown, INPUT_PULLUP);
  pinMode(led2Down, OUTPUT);
  
}

long off1 = 0;
long off2 = 0;

void loop()
{
  if( (digitalRead(led1Up) == LOW )&&(digitalRead(led2Down) == LOW )  && (digitalRead(buttonUp) == LOW)&& (digitalRead(buttonDown) == HIGH) ) //if LED is off  and button is pressed [low because it has pullup resistor]
  {
    digitalWrite(led1Up, HIGH);

   
    off1 = millis() + 5000; //store var of now + 5 seconds
    
  }
 
  if(digitalRead(led1Up) == HIGH    ) //if led is on
   
       
     if(millis() >= off1 ||  ( digitalRead(buttonUp) == LOW  && off1 - millis() > 250 && off1 - millis() < 5000 )  ) //see if it's time to turn off LED
     
      {
        
         
         digitalWrite(led1Up, LOW); //it's time. this also re-enables the button
         
      }


//for second button
if( (digitalRead(led2Down) == LOW )&&(digitalRead(led1Up) == LOW ) && (digitalRead(buttonDown) == LOW) && (digitalRead(buttonUp) == HIGH) ) //if LED is off  and button is pressed [low because it has pullup resistor]
  {
    digitalWrite(led2Down, HIGH);

   
    off2 = millis() + 5000; //store var of now + 5 seconds
   
  }
 
  if(digitalRead(led2Down) == HIGH) //if led is on
  
      if(millis() >= off2) //see if it's time to turn off LED
      {
         digitalWrite(led2Down, LOW); //it's time. this also re-enables the button
       
      }    
  }

OK I see it wasn't optimal. Just to get you going, try this:

if(millis() >= off1 ||  ( digitalRead(buttonUp) == LOW  && off1 - millis() < 4750 )  ) //see if it's time to turn off LED

If that doesn't work, revert to your original sketch and try this:

{
   digitalWrite(led1Up, HIGH);

   delay( 250 ) ;  // NEW LINE - not nice but quick 
   off1 = millis() + 5000; //store var of now + 5 seconds
  
 }

In both cases, the button should be pressed for less than 250 seconds or there will be a problem.

If all that doesn't help, then maybe a complete rething is necessary.

PaulMurrayCbr:
Oh. I thought he was talking about a car alarm.

That would also be plausible and I had to read the description carefully to rule it out. 220volts, however, sounds more like a domestic electrical system. Maybe the OP will confirm ?

Good morning or Good evening. PaulMurrayCbr is for domestic use of windows-doors electric shouters.Relays are 12v input and 230v 10A output.I will just put 2 extra 5v in order to control all the other from arduino(only for the master use).
Locally the shouters works from each room.So without the modification which we are trying to do, if i connect arduino with the current program,When i push the button up (from master) all the shouters go up until the expire of 5s for example(actually i will put 9s deadline). Also the buttonDown does not work(either i push it or not) until the led1up turns off.The same is the function when i push buttonDown.
Now i want to have a second choice which will allow me to turn the led1up off before the expire of the 5s sec by pushing the buttonUp again.Now if i push the buttonUp again after the first time nothing happens and the led1 stays on until the expire of time.I believe that now i explained well!

Sir 6v6gt i put your code inside but i noticed that when i push the button again after the first time it just reloads the delay while the ledUp1 stays on until the expire of time.

The first code you gave me it seems to work but with a lot of problems(once it works once it does not works)
if(millis() >= off1 || digitalRead(buttonUp) == LOW ) //see if it's time to turn off LED

int led1Up = 2;
int led2Down = 3;
int buttonUp = 4;
int buttonDown = 6;
void setup()
{
  pinMode(buttonUp, INPUT_PULLUP);
  pinMode(led1Up, OUTPUT);
   pinMode(buttonDown, INPUT_PULLUP);
  pinMode(led2Down, OUTPUT);
 
}

long off1 = 0;
long off2 = 0;

void loop()
{
  if( (digitalRead(led1Up) == LOW )&&(digitalRead(led2Down) == LOW )  && (digitalRead(buttonUp) ==

LOW)&& (digitalRead(buttonDown) == HIGH) )
  {
    digitalWrite(led1Up, HIGH);

   
    off1 = millis() + 5000; //store var of now + 5 seconds
   
  }
 
  if(digitalRead(led1Up) == HIGH    ) //if led is on
   
       
 if(millis() >= off1 ||  ( digitalRead(buttonUp) == LOW  && off1 - millis() < 4750 )  ) //see if it's time to turn off LED
      {
         digitalWrite(led1Up, LOW); //it's time. this also re-enables the button
         
      }

//for the second button
if( (digitalRead(led2Down) == LOW )&&(digitalRead(led1Up) == LOW ) && (digitalRead(buttonDown) == LOW) && (digitalRead(buttonUp) == HIGH) ) //if LED is off  and button is pressed [low because it has pullup resistor]
  {
    digitalWrite(led2Down, HIGH);

   
    off2 = millis() + 5000; //store var of now + 5 seconds
   
  }
 
  if(digitalRead(led2Down) == HIGH)
 
      if(millis() >= off2)
      {
         digitalWrite(led2Down, LOW);
       
      }   
  }

In that case, it is shutters and not shouters.

OK sometimes you can get away with a quick hack. In this case it was not a good idea. Really, you need to start again using a proper state model to ensure all possibilities are covered. I quickly did this in Excel. Does this express your requirements:

Hello 6v6gt.You are correct.It is what i want to do.I think that the third vertical line is not absolutely necessarie because if i want to make the shouters move down i can just push the buttonDown.But it is not bad, as you wrote it is more correct .

maybe this gets you a bit closer to a solution based on your code and the state model above:

int led1Up = 2;
int led2Down = 3;
int buttonUp = 4;
int buttonDown = 6;


enum State {
  MOVING_UP = 1 ,
  MOVING_DOWN,
  STOPPED
} state ;


boolean buttonPressed( byte buttonPin ) {
  // with crude button debounce
  if ( digitalRead( buttonPin ) == LOW ) {
    delay( 500 ) ;
    return true ;
  }
  else {
    return false ;
  }
}



void setup()
{
  pinMode(buttonUp, INPUT_PULLUP);
  pinMode(led1Up, OUTPUT);
  pinMode(buttonDown, INPUT_PULLUP);
  pinMode(led2Down, OUTPUT);
  state = STOPPED ;

}


void loop()
{

  static unsigned long upButtonPressedAtMs ;
  static unsigned long downButtonPressedAtMs ;

// actions dependent on current state
  if ( state == STOPPED ) {
    digitalWrite( led1Up, false ) ;
    digitalWrite( led2Down, false ) ;
  }
  else if ( state == MOVING_UP ) {
    digitalWrite( led1Up, true ) ;
    digitalWrite( led2Down, false ) ;
  }
  else if ( state == MOVING_DOWN ) {
    digitalWrite( led1Up, false ) ;
    digitalWrite( led2Down, true ) ;
  }



// check if a state transition necessary

  if ( state == MOVING_UP && millis() - upButtonPressedAtMs > 5000 ) {
    state = STOPPED ;
  }

  if ( state == MOVING_UP &&  buttonPressed( buttonUp ) ) {
    state = STOPPED ;
  }

  if ( state == MOVING_UP &&  buttonPressed( buttonDown ) ) {
    downButtonPressedAtMs = millis() ;
    state = MOVING_DOWN ;
  }


  if ( state == MOVING_DOWN && millis() - downButtonPressedAtMs > 5000 ) {
    state = STOPPED ;
  }

  if ( state == MOVING_DOWN &&  buttonPressed( buttonDown ) ) {
    state = STOPPED ;
  }

  if ( state == MOVING_DOWN &&  buttonPressed( buttonUp ) ) {
    upButtonPressedAtMs = millis() ;
    state = MOVING_UP ;
  }


  if ( state == STOPPED && buttonPressed( buttonUp ) ) {
    upButtonPressedAtMs = millis() ;
    state = MOVING_UP ;
  }

   if ( state == STOPPED && buttonPressed( buttonDown ) ) {
    downButtonPressedAtMs = millis() ;
    state = MOVING_DOWN ;
  }

}

It works perfectly!Thank you a lot for your time you spent in order to write your code!You did all the job by yourself!

I think that this topic can close now!

Hello !So your circuit as master works perfectly!I tried to make a modification to your circuit.I don't like my local connection of button(locally) because i have to have my hand at the button in order to move down or up.If i let the button the shouters stops immediately. So i used your circuit for local buttons(and not for masters) by making some extra copy-paste button according to your circuit. For example i made 4 push buttons for 2 electric shouters.What i am trying to do is to put 2 extra button near to the central door(as master) in order to control the 2 shouters. now in your sketch there are 6 buttons and i want the buttonUp10 = 10; //master up to turn on all the Ledup and buttonDown11 = 11; //master down to control the LedDown.I try to make it work but i am very confused.I believe that with this modification the circuit will be perfect.It works well now but i don't want to keep pushing the button locally until the shouters move up or down.I want the same procedure as with masters!
I am sorry for the annoyance.
Below is an example jpg of 4 local wall button and a master of 2 buttons(up and down).As you can see in order to move down or up the shouters i have to keep pressing the button.If i let the hand it immediately stops(it is a little irritating to keep pressing the button).

int led1Up = 2;
int led2Down = 3;
int led7Up = 7;
int led8Down = 8;

int buttonUp1 = 4;
int buttonDown2 = 6;

int buttonUp9 = 9;
int buttonDown12 = 12;

int buttonUp10 = 10; //master up, with this button i want to turn on in the same time led1Up and led7Up
int buttonDown11 = 11; //master down,with this button i want to turn on in the same time led2Down and led8Down

enum State {
  MOVING_UP = 1 ,
  MOVING_DOWN,
  STOPPED
} state ;


enum State1 {
  MOVING_UP1 = 1 ,
  MOVING_DOWN1,
  STOPPED1
} state1 ;


enum State2 {
  MOVING_UP2 = 1 ,
  MOVING_DOWN2,
  STOPPED2
} state2 ;


boolean buttonPressed( byte buttonPin ) {
  // with crude button debounce
  if ( digitalRead( buttonPin ) == LOW ) {
    delay( 500 ) ;
    return true ;
  }
  else {
    return false ;
  }
}




boolean buttonPressed1( byte buttonPin1 ) {
  // with crude button debounce
  if ( digitalRead( buttonPin1 ) == LOW ) {
    delay( 500 ) ;
    return true ;
  }
  else {
    return false ;
  }
}

boolean buttonPressed2( byte buttonPin2 ) {
  // with crude button debounce
  if ( digitalRead( buttonPin2 ) == LOW ) {
    delay( 500 ) ;
    return true ;
  }
  else {
    return false ;
  }
}





void setup()
{
  pinMode(buttonUp1, INPUT_PULLUP);
  pinMode(led1Up, OUTPUT);
  pinMode(buttonDown2, INPUT_PULLUP);
  pinMode(led2Down, OUTPUT);
  state = STOPPED ;


pinMode(buttonUp9, INPUT_PULLUP);
  pinMode(led7Up, OUTPUT);
  pinMode(buttonDown12, INPUT_PULLUP);
  pinMode(led8Down, OUTPUT);
  state1 = STOPPED1 ;


pinMode(buttonUp10, INPUT_PULLUP);

  pinMode(buttonDown11, INPUT_PULLUP);

  state2 = STOPPED2 ;


}

void loop()
{

  static unsigned long upButtonPressedAtMs ;
  static unsigned long downButtonPressedAtMs ;
 static unsigned long upButtonPressedAtMs1 ;
  static unsigned long downButtonPressedAtMs1 ;
  static unsigned long upButtonPressedAtMs2 ;
  static unsigned long downButtonPressedAtMs2 ;

// actions dependent on current state
  if ( state == STOPPED  ) {
    digitalWrite( led1Up, true ) ;
    digitalWrite( led2Down, true ) ;
 

    
  }
  else if ( state == MOVING_UP ) {
    digitalWrite( led1Up, true ) ;
    digitalWrite( led2Down, false ) ;
 

 
    
  }
  else if ( state == MOVING_DOWN ) {
    digitalWrite( led1Up, false ) ;
    digitalWrite( led2Down, true ) ;

    
  }



// check if a state transition necessary

  if ( state == MOVING_UP && millis() - upButtonPressedAtMs > 5000 ) {
    state = STOPPED ;
  }

  if ( state == MOVING_UP &&  buttonPressed( buttonUp1 ) ) {
    state = STOPPED ;
  }

  if ( state == MOVING_UP &&  buttonPressed( buttonDown2 ) ) {
    downButtonPressedAtMs = millis() ;
    state = MOVING_DOWN ;
  }


  if ( state == MOVING_DOWN && millis() - downButtonPressedAtMs > 5000 ) {
    state = STOPPED ;
  }

  if ( state == MOVING_DOWN &&  buttonPressed( buttonDown2 ) ) {
    state = STOPPED ;
  }

  if ( state == MOVING_DOWN &&  buttonPressed( buttonUp1 ) ) {
    upButtonPressedAtMs = millis() ;
    state = MOVING_UP ;
  }


  if ( state == STOPPED && buttonPressed( buttonUp1 ) ) {
    upButtonPressedAtMs = millis() ;
    state = MOVING_UP ;
  }

   if ( state == STOPPED && buttonPressed( buttonDown2 ) ) {
    downButtonPressedAtMs = millis() ;
    state = MOVING_DOWN ;
  }




// actions dependent on current state
  if ( state1 == STOPPED1 ) {
    digitalWrite( led7Up, true ) ;
    digitalWrite( led8Down, true ) ;
  }
  else if ( state1 == MOVING_UP1 ) {
    digitalWrite( led7Up, true ) ;
    digitalWrite( led8Down, false ) ;
  }
  else if ( state1 == MOVING_DOWN1 ) {
    digitalWrite( led7Up, false ) ;
    digitalWrite( led8Down, true ) ;
  }


// check if a state transition necessary

  if ( state1 == MOVING_UP1 && millis() - upButtonPressedAtMs1 > 5000 ) {
    state1 = STOPPED1 ;
  }

  if ( state1 == MOVING_UP1 &&  buttonPressed1( buttonUp9 ) ) {
    state1 = STOPPED1 ;
  }

  if ( state1 == MOVING_UP1 &&  buttonPressed1( buttonDown12 ) ) {
    downButtonPressedAtMs1 = millis() ;
    state1 = MOVING_DOWN1 ;
  }


  if ( state1 == MOVING_DOWN1 && millis() - downButtonPressedAtMs1 > 5000 ) {
    state1 = STOPPED1 ;
  }

  if ( state1 == MOVING_DOWN1 &&  buttonPressed1( buttonDown12 ) ) {
    state1 = STOPPED1 ;
  }

  if ( state1 == MOVING_DOWN1 &&  buttonPressed1( buttonUp9 ) ) {
    upButtonPressedAtMs1 = millis() ;
    state1 = MOVING_UP1 ;
  }


  if ( state1 == STOPPED1 && buttonPressed1( buttonUp9 ) ) {
    upButtonPressedAtMs1 = millis() ;
    state1 = MOVING_UP1 ;
  }

   if ( state1 == STOPPED1 && buttonPressed1( buttonDown12 ) ) {
    downButtonPressedAtMs1 = millis() ;
    state1 = MOVING_DOWN1 ;
  }


// actions dependent on current state
  if ( state2 == STOPPED2  ) {
    digitalWrite( led1Up, true ) ;
    digitalWrite( led2Down, true ) ;
 
   digitalWrite( led7Up, true ) ;
   digitalWrite( led8Down, true ) ;
  }
  else if ( state2 == MOVING_UP2 ) {
    digitalWrite( led1Up, true ) ;
    digitalWrite( led2Down, false ) ;
    
    digitalWrite( led7Up, true ) ;
   digitalWrite( led8Down, false ) ;

 
    
  }
  else if ( state2 == MOVING_DOWN2 ) {
    digitalWrite( led1Up, false ) ;
    digitalWrite( led2Down, true ) ;

    digitalWrite( led7Up, false ) ;
   digitalWrite( led8Down, true ) ;
    
  }


// check if a state transition necessary

  if ( state2 == MOVING_UP2  && millis() - upButtonPressedAtMs2 > 5000)   {
    state2 = STOPPED2;
     
  }

  if ( state2 == MOVING_UP2  && buttonPressed2( buttonUp10 )) {
    state2 = STOPPED2 ;
  
  }

  if ( state2 == MOVING_UP2 &&  buttonPressed2( buttonDown11)) {
    downButtonPressedAtMs2 = millis() ;
    state2 = MOVING_DOWN2 ;
  
  }


  if ( state2 == MOVING_DOWN2 && millis() - downButtonPressedAtMs2 > 5000) {
    state2 = STOPPED2 ;
     state = STOPPED ;
  }

  if ( state2 == MOVING_DOWN2 &&  buttonPressed2( buttonDown11 ) ) {
    state2 = STOPPED2 ;
    state = STOPPED ;
  }

  if ( state2 == MOVING_DOWN2 &&  buttonPressed2( buttonUp10 ) ) {
    upButtonPressedAtMs2 = millis() ;
    state2 = MOVING_UP2 ;
  }


  if ( state2 == STOPPED2 && buttonPressed2( buttonUp10 ) ) {
    upButtonPressedAtMs2 = millis() ;
    state2 = MOVING_UP2 ;
  }

   if ( state2 == STOPPED2 && buttonPressed2( buttonDown11 ) ) {
    downButtonPressedAtMs2 = millis() ;
    state2 = MOVING_DOWN2 ;
  }





}

jpg

Hello Guys!Sir 6v6gt unfortunately there are problems with the new code.

firstly with the local panels and then with the master panel.

local panell1 works good but when i push the button(either button1Up or button1Down) again after the first push and before the expire of 5s, the led does not turn off but remain on until the expire of 5s.

Local panell2 has 2 problems.The first is the same as the panell1, and the second is when i push the

button2Down as a result led2Down turns on and then push immediately the button2Up(in order to turn off the led2Down and turn on the led2Up). I noticed that the led2Up does not turns on but blinks a while and stay off)

Now it is a little difficult to describe with words the mode off masters.The mode is not precise but very complicated.

if i push the buttonMasterUp the led1Up and the led2Up turns on (and wait the expire in order to turn off)
if i push the buttonMasterUp again after the expire of time the led1Up turns on and the led2Up stays off .
if i push the buttonMasterUp again after the expire of time the led1Up turns on and the led2Up turns on .

if i push the buttonMasterUp before the expire of time the led1Up turns on and the led2Up stays off .

all in all the procedure and the behavior is very strange.The same problem with buttonMasterDown.

// shutter 1
int led1Up = 2;           // some renaming here so a "1" refers to shutter 1 ; "2" refers to shutter 2 etc.
int led1Down = 3;
int button1Up = 4;
int button1Down = 6;

// shutter 2
int led2Up = 7;
int led2Down = 8;
int button2Up = 9;
int button2Down = 10;

// shutter master
int buttonMasterUp = 11 ;
int buttonMasterDown = 12 ;



boolean buttonPressed = false ;

enum State {
  MOVING_UP = 1 ,
  MOVING_DOWN,
  STOPPED
} state1, state2 ;


boolean downButtonPressed( byte buttonPin  ) {
  if ( digitalRead( buttonPin ) == LOW  || digitalRead( buttonMasterDown ) == LOW ) {
    buttonPressed = true ;
    return true ;
  }
  else {
    return false ;
  }
}

boolean upButtonPressed( byte buttonPin  ) {
  if ( digitalRead( buttonPin ) == LOW  || digitalRead( buttonMasterUp ) == LOW ) {
    buttonPressed = true ;
    return true ;
  }
  else {
    return false ;
  }
}



void setup()
{
  pinMode(button1Up, INPUT_PULLUP);
  pinMode(led1Up, OUTPUT);
  pinMode(button1Down, INPUT_PULLUP);
  pinMode(led1Down, OUTPUT);

  pinMode(button2Up, INPUT_PULLUP);
  pinMode(led2Up, OUTPUT);
  pinMode(button2Down, INPUT_PULLUP);
  pinMode(led2Down, OUTPUT);

  pinMode(buttonMasterUp, INPUT_PULLUP);
  pinMode(buttonMasterDown, INPUT_PULLUP);

  state1 = STOPPED ;
  state2 = STOPPED ;

}


void loop()
{

  static unsigned long upButton1PressedAtMs ;
  static unsigned long downButton1PressedAtMs ;

  static unsigned long upButton2PressedAtMs ;
  static unsigned long downButton2PressedAtMs ;

  // actions dependent on current state1

 // shutter 1
  if ( state1 == STOPPED ) {
    digitalWrite( led1Up, false ) ;
    digitalWrite( led1Down, false ) ;
  }
  else if ( state1 == MOVING_UP ) {
    digitalWrite( led1Up, true ) ;
    digitalWrite( led1Down, false ) ;
  }
  else if ( state1 == MOVING_DOWN ) {
    digitalWrite( led1Up, false ) ;
    digitalWrite( led1Down, true ) ;
  }

 
 // shutter 2
  if ( state2 == STOPPED ) {
    digitalWrite( led2Up, false ) ;
    digitalWrite( led2Down, false ) ;
  }
  else if ( state2 == MOVING_UP ) {
    digitalWrite( led2Up, true ) ;
    digitalWrite( led2Down, false ) ;
  }
  else if ( state2 == MOVING_DOWN ) {
    digitalWrite( led2Up, false ) ;
    digitalWrite( led2Down, true ) ;
  }



  // check if a state transition necessary

 // shutter 1

  if ( state1 == MOVING_UP && millis() - upButton1PressedAtMs > 5000 ) {
    state1 = STOPPED ;
  }

  if ( state1 == MOVING_UP &&  upButtonPressed( button1Up ) ) {
    state1 = STOPPED ;
  }

  if ( state1 == MOVING_UP &&  downButtonPressed( button1Down ) ) {
    downButton1PressedAtMs = millis() ;
    state1 = MOVING_DOWN ;
  }


  if ( state1 == MOVING_DOWN && millis() - downButton1PressedAtMs > 5000 ) {
    state1 = STOPPED ;
  }

  if ( state1 == MOVING_DOWN &&  downButtonPressed( button1Down ) ) {
    state1 = STOPPED ;
  }

  if ( state1 == MOVING_DOWN &&  upButtonPressed( button1Up ) ) {
    upButton1PressedAtMs = millis() ;
    state1 = MOVING_UP ;
  }


  if ( state1 == STOPPED && upButtonPressed( button1Up ) ) {
    upButton1PressedAtMs = millis() ;
    state1 = MOVING_UP ;
  }

  if ( state1 == STOPPED && downButtonPressed( button1Down ) ) {
    downButton1PressedAtMs = millis() ;
    state1 = MOVING_DOWN ;
  }

  // shutter 2

  if ( state2 == MOVING_UP && millis() - upButton2PressedAtMs > 5000 ) {
    state2 = STOPPED ;
  }

  if ( state2 == MOVING_UP &&  upButtonPressed( button2Up ) ) {
    state2 = STOPPED ;
  }

  if ( state2 == MOVING_UP &&  downButtonPressed( button2Down ) ) {
    downButton2PressedAtMs = millis() ;
    state2 = MOVING_DOWN ;
  }


  if ( state2 == MOVING_DOWN && millis() - downButton2PressedAtMs > 5000 ) {
    state2 = STOPPED ;
  }

  if ( state2 == MOVING_DOWN &&  downButtonPressed( button2Down ) ) {
    state2 = STOPPED ;
  }

  if ( state2 == MOVING_DOWN &&  upButtonPressed( button2Up ) ) {
    upButton1PressedAtMs = millis() ;
    state2 = MOVING_UP ;
  }


  if ( state2 == STOPPED && upButtonPressed( button2Up ) ) {
    upButton2PressedAtMs = millis() ;
    state2 = MOVING_UP ;
  }

  if ( state2 == STOPPED && downButtonPressed( button2Down ) ) {
    downButton2PressedAtMs = millis() ;
    state2 = MOVING_DOWN ;
  }


  if ( buttonPressed == true ) {
    buttonPressed = false ;
    delay( 500 ) ;  // crude debounce
  }

}