change onPressAsToggle() state in button.h with code

I'm using onPressAsToggle() with the button.h library. I have some momentary pushbutton switches I'm using and it's working pretty well. But under certain conditions I want to change the state of onPressAsToggle() with code. Essentially it would be as if I pressed the actual pushbutton. Anyone know how to do this?

I can't find that function in the button.h file available from the Playground. Where did you get button.h from ?
It would be helpful to see your full code and to know why you want/need to do what you describe.

I got the library from here: GitHub - carlynorama/Arduino-Library-Button: This is a library for adding buttons to Arduino projects. It supports events like OnPress and OnRelease.

I have 3 momentary pushbuttons controlling 3 things in a hot tub: On/Off for the hot tub, Air bubble pump, jets pump. There is a a small array, InputButtonsCurrentState[], that determines if any of these are on or off. For example, if InputButtonsCurrentState[BTN_HOT_TUB_ON_OFF] is HIGH, the hot tub is on. But if I want to turn the hot tub off with code (like if I get an error condition or something), I can't just go make InputButtonsCurrentState[BTN_HOT_TUB_ON_OFF] = LOW because the btnHotTub.onPressAsToggle() will just make it HIGH again. I need to toggle btnHotTub.onPressAsToggle(), but I don't know how.

My program is pretty large, but here's the parts that use the buttons

#include <Button.h>

//=== Push button Inputs ===
#define HOT_TUB_BUTTON_INPUT_PIN       53
#define JETS_BUTTON_INPUT_PIN          47
#define BUBBLER_BUTTON_INPUT_PIN       49

// Array for Input buttons, current state of hot tub, jets and bubbler
bool InputButtonsCurrentState[3];    
#define BTN_HOT_TUB_ON_OFF   0  // Hot tub On/Off Button
#define BTN_JETS_ON_OFF      1  // Jests On/Off Button
#define BTN_BUBBLER_ON_OFF   2  // Bubbler On/Off button


// Setup buttons.  Momentary push buttons are low when pressed
Button btnHotTub =  Button(HOT_TUB_BUTTON_INPUT_PIN, LOW);   
Button btnJets =    Button(JETS_BUTTON_INPUT_PIN,    LOW);
Button btnBubbler = Button(BUBBLER_BUTTON_INPUT_PIN, LOW);

void ReadInputButtons(){

  // Read button inputs 
  btnHotTub.listen();
  btnJets.listen();
  btnBubbler.listen();
    
  if (btnHotTub.onPressAsToggle()) 
  { InputButtonsCurrentState[BTN_HOT_TUB_ON_OFF] = HIGH; }  
  else 
  { InputButtonsCurrentState[BTN_HOT_TUB_ON_OFF] = LOW; }
  
  if (btnJets.onPressAsToggle()) 
  { InputButtonsCurrentState[BTN_JETS_ON_OFF] = HIGH; }
  else 
  { InputButtonsCurrentState[BTN_JETS_ON_OFF] = LOW; }

  if (btnBubbler.onPressAsToggle()) 
  { InputButtonsCurrentState[BTN_BUBBLER_ON_OFF] = HIGH; }  
  else  
  { InputButtonsCurrentState[BTN_BUBBLER_ON_OFF] = LOW; }
}

void setup(){
  pinMode(HOT_TUB_BUTTON_INPUT_PIN,     INPUT);
  pinMode(JETS_BUTTON_INPUT_PIN,        INPUT);
  pinMode(BUBBLER_BUTTON_INPUT_PIN,     INPUT);
}

void loop() {
  ReadInputButtons();
}

Hello,

I am trying to do a similar thing. I have a 2x2 sparkfun rubber buttons. Everything is fine when I use onPressAsToggle() to give it a colour to an RGB LED when I press the button (not the ones in the buttons) and when I press it again to turn of that LED.

The problem is that when I press a different button and any of the others are giving a colour, the colours mix together. I want to switch off any colour when I press a different button.

Is it possible with this library?

Thanks in advance and keep on the good work in this great community that is so helpful

Hello, ScottG

You could fix the problem?
as?

Thank you