# Arduino - detectar 2 botões ao mesmo tempo - Controlador MIDI

**URL:** <https://forum.fazedores.com/t/arduino-detectar-2-botoes-ao-mesmo-tempo-controlador-midi/7950>\
**Category:** Arduino\
**Created:** [Janeiro 23, 2021, 3:44am UTC](https://forum.fazedores.com/t/arduino-detectar-2-botoes-ao-mesmo-tempo-controlador-midi/7950 "2021-01-23T03:44:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msfrank](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@msfrank](https://forum.fazedores.com/u/msfrank)\
**Post date:** [Janeiro 23, 2021, 3:44am UTC](https://forum.fazedores.com/t/arduino-detectar-2-botoes-ao-mesmo-tempo-controlador-midi/7950/1 "2021-01-23T03:44:48Z")

</div>

Sou novo na programação com Arduíno, mas consegui criar um controlador MIDI, para usar com softwares simuladores de amplificadores de guitarra, como o Bias FX2.

Tenho 8 footswitches conectados a um Arduino Micro. Usei a biblioteca MIDI e também a Bounce2, e está funcionando muito bem. Mas, eu gostaria de adicionar a funcionalidade de apertar 2 footswitches “ao mesmo tempo”, e assim mandar mensagens MIDI diferentes. Não faço ideia se é possível fazer isso no Arduíno. Segue meu sketch abaixo:

// Including the Libraries  
#include \<USB-MIDI.h\>  
#include \<Bounce2.h\>

USBMIDI\_CREATE\_DEFAULT\_INSTANCE();

// Define number of Foot Switches (buttons), and the pin array  
#define NUM\_BUTTONS 8  
const uint8\_t BUTTON\_PINS[NUM\_BUTTONS] = {3, 4, 5, 6, 7, 8, 9, 10};

Bounce \* buttons = new Bounce[NUM\_BUTTONS];

void setup()  
{  
for (int i = 0; i \< NUM\_BUTTONS; i++)  
{  
buttons[i].attach( BUTTON\_PINS[i] , INPUT\_PULLUP );  
buttons[i].interval(25);  
}  
MIDI.begin(1);  
}

void loop()  
{

for (int i = 0; i \< NUM\_BUTTONS; i++)  
{  
buttons[i].update();  
if ( buttons[i].fell() )  
{  
MIDI.sendControlChange( i + 11, 127, 1);  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Anilson](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.fazedores.com/anilson/32/3410_2.png) [@Anilson](https://forum.fazedores.com/u/Anilson)\
**Post date:** [Janeiro 26, 2021, 4:39pm UTC](https://forum.fazedores.com/t/arduino-detectar-2-botoes-ao-mesmo-tempo-controlador-midi/7950/2 "2021-01-26T16:39:49Z")

</div>

Faz assim :  
int a;  
int b;  
int c;  
int d;  
////////////

if (digitalRead(4) == HIGH) { a= 1;}else{ a=0;}  
if (digitalRead(5) == HIGH) { b= 2;}else{ b=0;}  
if (digitalRead(6) == HIGH) { c=4;}else{ c=0;}  
d = a + b + c ;  
/ / A variável d tem o valor dos 3 buttons ao mesmo tempo.

---

<div class="post-metadata">

**Author:** ![tgalbuquerque](https://avatars.discourse-cdn.com/v4/letter/t/50afbb/32.png) [@tgalbuquerque](https://forum.fazedores.com/u/tgalbuquerque)\
**Post date:** [Setembro 26, 2021, 11:13pm UTC](https://forum.fazedores.com/t/arduino-detectar-2-botoes-ao-mesmo-tempo-controlador-midi/7950/3 "2021-09-26T23:13:11Z")

</div>

Boa noite!  
Duas perguntas:  
a) poderia me mandar os códigos e qual a biblioteca utilizada no seu projeto?  
b) Você usa algo como pedal de expressão?  
Desde já, agradeço.
