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
}
}