HELP ME PLEASE!!!__MIDI_CONTROLLER_Edge Detection for pushbuttons_ LEDS

Hello!!! I'm new in arduino programming. I've just used arduino for some small project and now I would like to create a midi controller to use it with a vj software.
I've connected all (arduino uno rev 3, 2 multiplexers 74HC4051, pushbuttons, pots, sliders) on my midi controller and all work well. Now I would add some leds as edge detection for pushbuttons.
I'm trying to modify the code but I'm stuck :frowning:

I found this tutorial on arduino website https://www.arduino.cc/en/Tutorial/StateChangeDetection

but I don't know how to modify and insert it in the code that I'm using for my project... I'v just add some string with led connected to multiplexers but I don't know how to go on...

I hope you could help me!!!
Please...
:grinning:

MIDI_Controller_v1-2_edge_detection.ino (8.26 KB)

You have a variable that holds the last state of your button read. Then you do a new button read and compare the two. If they are different you have detected an edge. At the end of the function you make the last state equal to the just read state.

newButton = digitalRead(buttonPin);
if(lastButton != newBotton) { // you have found an edge
// do what you want when an edge occurs
}
lastButton = newButton;

The variable lastButton must be a global or local static variable. You can see what sort of edge you have by examining the value of newButton inside the "if" statement in the code above. If it is a LOW you have a falling edge, if a HIGH a rising one.

Many thanks for your reply!