I have this:
https://www.sparkfun.com/products/9595? midi shield connected to my arduino. I decided to start simple with just a button or two. All of the simple button examples show a button sending a digital input high, but the shield I'm using connects the digital pin to ground when the switch is closed which confused me. So I looked at the example code and tried to pull out the bits that are pertinent to just utilizing two of the three buttons.
Here are the pertinent portions of the setup code:
#define BUTTON1 2
#define BUTTON2 3
#define STAT1 7
#define STAT2 6
void setup() {
Serial.begin(9600);
pinMode(STAT1,OUTPUT);
pinMode(STAT2,OUTPUT);
pinMode(BUTTON1,INPUT);
pinMode(BUTTON2,INPUT);
digitalWrite(BUTTON1,HIGH);
digitalWrite(BUTTON2,HIGH);
for(int i = 0;i < 10;i++) // flash MIDI Sheild LED's on startup
{
digitalWrite(STAT1,HIGH);
digitalWrite(STAT2,LOW);
delay(30);
digitalWrite(STAT1,LOW);
digitalWrite(STAT2,HIGH);
delay(30);
}
digitalWrite(STAT1,HIGH);
digitalWrite(STAT2,HIGH);
}
In the main loop the example code uses the buttons like this:
if(button(BUTTON1) || button(BUTTON2) || button(BUTTON3))
{
Midi_Send(0x90,note,0x45);
while(button(BUTTON1) || button(BUTTON2) || button(BUTTON3));
}
Can someone explain to me what is going on with the buttons in the main loop? This is the part that I don't get. I think that If I understood this I could get my sketch to react to a button push.
Thanks for stopping by.
Loren