New to Coding. I just want to make 4 midi push buttons work. I have loaded what was recommended and I am at a loss. Not sure what else to do.

void setup() {
Serial.begin(38400);
pinMode(8, INPUT_PULLUP);
}

void loop() {
if (digitalRead(8) == HIGH) {
Serial.println("Button is not pressed...");
} else {
Serial.println("Button pressed!!!");
}
delay(3000);
}
 
I got button 8 to work pressed not pressed. Trying to duplicate it for the other buttons. Here is what I did.

void setup() {
Serial.begin(38400);
pinMode(8, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
}

void loop() {
if (digitalRead(8) == HIGH) {
if (digitalRead(7) == HIGH) ;
if (digitalRead(6) == HIGH) ;
if (digitalRead(5) == HIGH) ;
if (digitalRead(4) == HIGH) ;
Serial.println("Button is not pressed...");
} else {
Serial.println("Button pressed!!!");
}
delay(250);

}
 
This code (msg #27) will have no effect for pins 4, 5, 6, 7.

It is difficult to help you because I do not understand what you are trying to accomplish. I am struggling to understand why you would add checks for 5 buttons, but only have 1 pair of pressed vs not pressed messages. If you want the code to show when any of the buttons is pressed (but not indicate which button), try this:

Code:
void setup() {
  Serial.begin(38400);
  pinMode(8, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(8) == HIGH
      && digitalRead(7) == HIGH
      && digitalRead(6) == HIGH
      && digitalRead(5) == HIGH
      && digitalRead(4) == HIGH) {
    Serial.println("None of the button are pressed...");
  } else {
    Serial.println("One or more buttons pressed!!!");
  }
  delay(250);
}

But maybe this is not what you really wanted? I'm trying to help, but my only choices are guesswork or no answer at all.

Here is another guess.... a program which prints all 5 of them on a single line. Again, not sure if this is what you wanted, but it should at least be helpful for testing your hardware.

Code:
void setup() {
  Serial.begin(38400);
  pinMode(8, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  delayMicroseconds(10); // allow time for input voltages to stablize
}

void loop() {

  Serial.print("D4:");
  if (digitalRead(4) == LOW) {
    Serial.print("Pressed,  ");
  } else {
    Serial.print("released, ");
  }
  Serial.print("D5:");
  if (digitalRead(5) == LOW) {
    Serial.print("Pressed,  ");
  } else {
    Serial.print("released, ");
  }
  Serial.print("D6:");
  if (digitalRead(6) == LOW) {
    Serial.print("Pressed,  ");
  } else {
    Serial.print("released, ");
  }
  Serial.print("D7:");
  if (digitalRead(7) == LOW) {
    Serial.print("Pressed,  ");
  } else {
    Serial.print("released, ");
  }
  Serial.print("D8:");
  if (digitalRead(8) == LOW) {
    Serial.print("Pressed");
  } else {
    Serial.print("released");
  }
  Serial.println();
  delay(250);
}
 
Per the code you sent, all 4 buttons work with pressed and released. That is what I was trying to do. Im positive on my first try I could not of come up with that code. I appreciate the help. Since the buttons are now working, I need to figure out how the board is recognized as midi buttons. or am I putting the cart before the horse?
 
Next step is to learn how to run MIDI-OX (if using Windows) or similar software on MacOS or Linux if you use those. This is important because you need to see all incoming MIDI messages to know if Teensy is sending, and to see exactly what your PC receives.

I recommend first testing MIDI-OX with a known-good MIDI device like a musical keyboard.
 
Now that you know the pushbuttons work, might as well give the original MIDI buttons program a try. Of course edit the pin numbers. If it works exactly as you wanted, then you're done! If not, get MIDI-OX.

MIDI-OX is a free program. You should get it and learn how to view the MIDI messages from your MIDI keyboard.

Then when you view the MIDI messages Teensy transmits, you'll have confidence in using it from experience with your MIDI keyboard.
 
Good morning. Just updating you. Everything is working great. Thank you for all your help. Is there a good course to take to help to learn coding?
 
Back
Top