code with 2 buttons and 2 leds help please :)

hi, i need help with this code, i have problems at compile!!

this code is for switching direction for massage chair motor using 2 relays
i want when i press the first button to enable relay1 one for 30sec after delay 1sec and enable relay 2 for 30sec delay 1sec again and continue looping this until i press the button2
when i press button 2 i want to enable relay 1 for 30sec and after one loop i want everything stopped until i press again the button1 to start the first loop

thanks everyone for your time!!
:slight_smile:

#include <Button.h> 

Button Button1 = Button1(10, INPUT_PULLUP);
Button Button2 = Button2(11, INPUT_PULLUP);


void setup(){
 pinMode (10, INPUT);
 pinMode (11, INPUT);
 pinMode (5, OUTPUT);
 pinMode (6, OUTPUT);
}

void loop(){
 if (Button1.isPressed()){ 
  digitalWrite(5, HIGH);
   delay(30000);
   digitalWrite(5, LOW);
   delay(1000);
   digitalWrite(6, HIGH);
   delay(30000);
   digitalWrite(6, LOW);
   delay(1000); 
  }
 else if (Button2.isPressed()) {
    digitalWrite(5, HIGH);
   delay(3000);
   digitalWrite(5, LOW); 
    }
    
 }

i have problems at compile

Post the complete error message here

Button Button1 = Button1(10, INPUT_PULLUP);
Button Button2 = Button2(11, INPUT_PULLUP);

Is that the correct syntax for creating instances of Button ?

Button Button1(10, INPUT_PULLUP);
Button Button2(11, INPUT_PULLUP);

Seems more likely

the errors i have after change this

Button Button1 = Button1(10, INPUT_PULLUP);
Button Button2 = Button2(11, INPUT_PULLUP);

with this

Button Button1(10, INPUT_PULLUP);
Button Button2(11, INPUT_PULLUP);

errors:

sketch_mar18a:3: error: no matching function for call to 'Button::Button(int, int)'

Button Button1(10, INPUT_PULLUP);

^

C:\Users\Bilakoss\Documents\Arduino\sketch_mar18a\sketch_mar18a.ino:3:32: note: candidates are:

In file included from C:\Users\Bilakoss\Documents\Arduino\sketch_mar18a\sketch_mar18a.ino:1:0:

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:14:3: note: Button::Button(uint8_t)

Button(uint8_t pin);

^

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:14:3: note: candidate expects 1 argument, 2 provided

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: constexpr Button::Button(const Button&)

class Button

^

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: candidate expects 1 argument, 2 provided

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: constexpr Button::Button(Button&&)

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: candidate expects 1 argument, 2 provided

sketch_mar18a:4: error: no matching function for call to 'Button::Button(int, int)'

Button Button2(11, INPUT_PULLUP);

^

C:\Users\Bilakoss\Documents\Arduino\sketch_mar18a\sketch_mar18a.ino:4:32: note: candidates are:

In file included from C:\Users\Bilakoss\Documents\Arduino\sketch_mar18a\sketch_mar18a.ino:1:0:

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:14:3: note: Button::Button(uint8_t)

Button(uint8_t pin);

^

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:14:3: note: candidate expects 1 argument, 2 provided

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: constexpr Button::Button(const Button&)

class Button

^

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: candidate expects 1 argument, 2 provided

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: constexpr Button::Button(Button&&)

C:\Users\Bilakoss\Documents\Arduino\libraries\Button/Button.h:11:7: note: candidate expects 1 argument, 2 provided

C:\Users\Bilakoss\Documents\Arduino\sketch_mar18a\sketch_mar18a.ino: In function 'void loop()':

sketch_mar18a:15: error: 'class Button' has no member named 'isPressed'

if (Button1.isPressed()){

^

sketch_mar18a:25: error: 'class Button' has no member named 'isPressed'

else if (Button2.isPressed()) {

^

exit status 1 no matching function for call to 'Button::Button(int, int)'

Which button library are you using ?

this is my library!!!

Button.zip (4.97 KB)

In the library example the button objects are created like this

Button button1(2); // Connect your button between pin 2 and GND
Button button2(3); // Connect your button between pin 3 and GND
Button button3(4); // Connect your button between pin 4 and GND

The function in the library that creates the button objects takes one paramater, the pin number

        Button(uint8_t pin);

but you have used a different syntax

Button Button1 = Button1(10, INPUT_PULLUP);

Change your code to match that of the library