Button library guidance please. Thank you very much!

Hi,

I have a project going to replace the pedal board connected to my guitar amplifier. I'm hoping to get some help & guidance. Pedal board has 4 buttons.

Button A - controls which one of the 2 channels the amplifier is to switch to. Clean vs Distortion channel
Button B - controls a boost function which elevates volume level
Button C - controls a reverb function
Button D - controls an external effects loop function

Problem is with the buttons B, C & D. This being an analog tube amplifier these buttons do not have a recollection of their last state for each channel. What makes sense for B, C & D in clean channel does not necessarily make sense for the distortion channel. So each time I go between channels I find myself stomping the other buttons to get the B, C & D in the right state which is a bummer...

I rigged up a nice 4 button (momentary) replacement pedal and created a hardware interface to my Uno board to drive 4 relays which will replace the 4 stomp buttons found on the actual pedal. The hardware part of the project is all done and I am able to control the amplifier with the 4 buttons just like its original pedal. I am very pleased with how fast the hardware part of my mission came together. See photos below.

Now for the programming part... I am quite lazy and love reuse, recycle. Thanks for all the sharing in the community. I needed a debounce library to help me handle the momentary switches and also keep track of state such that one press turns function on and next press turns it off.

I came across Carlynorama's excellent button library (ref GitHub - carlynorama/Arduino-Library-Button: This is a library for adding buttons to Arduino projects. It supports events like OnPress and OnRelease.) and very quickly got my 4 button pedal working. Now is the time to implement the memory function such that for each state of Button A, states of buttons B, C & D are stored and recalled when button A state changes.

I opted to use a 2 x 3 matrix array to store the button states that are to be recalled and am able to keep track of them. I am able to set the relays programmatically as well but I came to the conclusion thats not the best way to go. Since the Buttons library is event driven I need to fire off the buttonB.onPressAsToggle() event rather than directly manipulate the relay. Reason for this is the simple On/Off state tracking that the buttons library provides. If I directly manipulate the relay then the library does not know the state of a button has changed so when I actually press that button for another manual change the control actually does not work...

So to cut a long story short, kindly let me know if there is a way to trigger the .onPressAsToggle() event in this library. The public functions don't seem to provide a way to do this and I am not proficient enough to modify the library to do what I need. If there is another library I can use instead kindly point me towards it. Thank you very very much!!!

Photos of my project. Thanks for looking.

I totally am not getting what exactly what your trying to do but why not just call the buttonB.onPressAsToggle() function when A is clicked?

I apologize for the confusing description above. I did try calling the buttonChannel.onPressAsToggle() but it does not appear to work that way. It is a listener function which reports when the button is pressed. It does not seem to allow me to trigger the button press. I might need to look for another library that might allow me to trigger button presses to control the state of one button when the other one is pressed.

Forget trying to use this and just write your own function that does what you want.

Grumpy_Mike:
Forget trying to use this and just write your own function that does what you want.

I guess I will end up doing just that. I was too lazy to think the debounce matters through with 4 buttons involved etc. The Buttons library seem to work nicely so I was hoping to leverage the good work already done. Any other button library out there which allows you to fire off button press events? Thanks much for all your help.

signed, lazy & hopeful! :smiley:

debouncing without using a library is covered in the tutorials section

http://arduino.cc/it/Tutorial/Debounce

I'm having trouble taking the tutorial and scaling it up to manage 4 buttons at the same time. It is not as smooth as the Button library mentioned above. I really want to make the library work. It works very smoothly. Researching continues.