Using Bounce library with multiplexer

Status
Not open for further replies.

JotaEfe13

Well-known member
Hi. In my project I have currently 8 tact switches connected directly to my Teensy 3.6 and I am using the Bouce library and its fallingEdge() method for a quick response of the buttons being pressed.

Is it possible to use the Bounce library with the mux? I have searched in the forum and in the web but I have not found any reference to this.

I have a 74HC4051E mux and I want it to control the 8 buttons. For the hardware hookup I have followed the section "Connecting Many Buttons & Knobs/Sliders" here, but I don't know how to implement the proposed code.

Code:
  // select 74HC4051 channel 5 (of 0 to 7)
  digitalWrite(1, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  
  // allow 50 us for signals to stablize
  delayMicroseconds(50);
  
  // read the signals routed to pin 10
  // through channel 5 of each 74HC4051 chip
  buttonPin10channel5.update();

How can I use now something like this?
Code:
if (buttonMenu.fallingEdge()) {
   // do something
}
 
I do not know if it will work but it seems as though it should. You currently have 8 bounce objects all with a different pin. And you call the update function for each of those in turn.

Conceptually, when you add the mux you would have 8 bounce objects all connected to the same pin. Before you call each update function, you would need to set the proper address on the mux. Then everything else would be the same.

A slight delay may be needed after you change the mux address lines.
 
Thank you, rcarr, it worked.
I was confused about the mapping of the pins for the Bounce objects, as all buttons share the same pin. But creating 8 different objects routed to the same pin and updating them after adressing the mux did the job.
 
Status
Not open for further replies.
Back
Top