MIDI LED lights via Nano 2.0

PaulRB:
Your stripboard seems bigger, in terms of strips x holes?

Don't forget that fritzing will let you cut a strip between holes. In practice that's very difficult. So when you cut a track in fritzing, do it on both sides of a hole.

Yes. I found it harder to fit the pieces the way I wanted in Fritzing, so I basically just wanted to get the circuit right.
So I made the board bigger.

Does the circuit seem correct to you in general now?

Well, I get the feeling we are reasonably happy with the schematic. If Fritzing is happy that that the schematic and the stripboard layouts match, that's a pretty good sign. Now you need to squeeze it down, which may not be easy because Fritzing does not show a perfect "bird's eye view" like your other stripboard app does. But that other app could not cross-check the layout against a schematic, i'm guessing? No single app is perfect.

Just wanted to drop in here and thank Paul and Paul for all your help and thoughts.
A while ago I finished my little build and it works brilliantly.

The only issue I've got left is how I solved the off-board wiring. I used male and female break away headers for the convenience while testing, but now I guess they could possibly fall out if I shake the enclosure.
One thought is to glue the headers together with hot glue (to not have to solder anything more), but that could be bad I guess.
Maybe it's just better if I remove the female headers and solder the male headers (attached to the wires) to the board?

Anyway - thanks, again.

I would be tempted to merely glue the male and female connectors together with hot melt. Makes future servicing easier.

Now they could oxidise over time (Makes future servicing more likely!) - perhaps put silica gel and an antioxidant sachet in the box.

Bumping my own thread here.
Seems like I've got issues with the code here.

When I send 5 MIDI notes at the same time - the only LED blinking is from D3. When I use them one at a time they all work separately.
If someone's got a few minutes over I'd love some assistance.
I'd love for each of the five ports to get the LEDs to blink both on separate notes and when I send 5 MIDI notes at the same time.

Unfortunately the code I've got in my Nano right now is on another computer, so I don't have it - but it's something like this (however - I can't even compile this):

byte commandByte;
byte noteByte;
byte velocityByte;
byte NoteOn=144; 

void setup(){
  Serial.begin(31250);
  pinMode(3,OUTPUT);
  digitalWrite(3,LOW);
  pinMode(4,OUTPUT);
  digitalWrite(4,LOW);
  pinMode(6,OUTPUT);
  digitalWrite(6,LOW);
  pinMode(9,OUTPUT);
  digitalWrite(9,LOW);
  pinMode(10,OUTPUT);
  digitalWrite(10,LOW);
}

void checkMIDI(){
  do{
    if (Serial.available()){

      commandByte = Serial.read();
      noteByte = Serial.read();
      velocityByte = Serial.read();
   
if (commandByte == NoteOn){

  if (noteByte == 60){
  digitalWrite(3,HIGH);
  delay(100);}

  else if (noteByte == 61){
  digitalWrite(4,HIGH);
  delay(100);}

  else if (noteByte == 62){
  digitalWrite(6,HIGH);
  delay(100);}

  else if (noteByte == 63){
  digitalWrite(9,HIGH);
  delay(100);}

  else if (noteByte == 64){
  digitalWrite(10,HIGH);
  delay(100);}
  
  }}}
  
  while (Serial.available()>2);}

void loop(){
  checkMIDI();
  delay(100);
  digitalWrite(3,LOW);
  digitalWrite(4,LOW);
  digitalWrite(6,LOW);
  digitalWrite(9,LOW);
  digitalWrite(10,LOW);
  }

Well, no point spending too much time reading code that isn't the actual running code.... but... i can see a likely source of problems in what you have posted: "delay(100);"

Before you post the actual code, please make sure to do Tools-->Auto Format before you post it. Harder to spot errors in incorrectly formatted/indented code.

Remove all the delays and only turn off the LEDs when you get a note off message.

Just following out of interest :slight_smile:

Trying with note off. Can't get this to compile, though.

byte commandByte;
byte noteByte;
byte velocityByte;
byte NoteOn = 144;
byte NoteOff = 128;

void setup() {
  Serial.begin(31250);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}

void loop() {

  do {
    if (Serial.available()) {


      commandByte = Serial.read();
      noteByte = Serial.read();
      velocityByte = Serial.read();

      if (commandByte == NoteOn) {
        digitalWrite(noteByte - 57, HIGH);
      }

      if (commandByte == NoteOff) {
        digitalWrite(noteByte - 57, LOW);
      }
    }
    while (Serial.available() > 2);

  }

Error log:

/Documents/Arduino/sketch_apr20e/sketch_apr20e.ino: In function 'void loop()':
sketch_apr20e:38: error: expected 'while' at end of input
   }
   ^
sketch_apr20e:38: error: expected '(' at end of input
sketch_apr20e:38: error: expected primary-expression at end of input
sketch_apr20e:38: error: expected ')' at end of input
sketch_apr20e:38: error: expected ';' at end of input
sketch_apr20e:38: error: expected '}' at end of input
exit status 1
expected 'while' at end of input

try

while (Serial.available() > 2) { ; }

ah, just re-read..

remove the } after the while..

Thanks. Unfortunately none of that is working.

void loop() {

    if (Serial.available() > 2) {

      commandByte = Serial.read();
      noteByte = Serial.read();
      velocityByte = Serial.read();

      if (commandByte == NoteOn) {
        digitalWrite(noteByte - 57, HIGH);
      }

      if (commandByte == NoteOff) {
        digitalWrite(noteByte - 57, LOW);
      }
    }
 
  }

Oh, great.

Now it works with lighting one port at a a time through MIDI.
I would however want it to be able to light all five ports at the same time.

Any suggestions?

If someone could help me with a code that lets me play five MIDI notes that lights five different LED strips I'd be so, so, so happy.

I'd really want it to work by tomorrow (the plan is to use it on stage then), and I've got a bunch of other stuff to deal with.
It would make my day.

It should do that, i think (i am no midi expert). If the "note off" for the first note arrives before the "note on" for the second note, then you will only get one channel on at a time. Is that what your midi keyboard is sending?

Yeah, I should have been more clear - it works to put one MIDI note at a time at the moment - but I want to benable to have all five LEDs to light up at the same time as well when I want to.

I've seen video clips of people doing this, so I guess it's not impossible - I just need to have the right code.

The line "digitalWrite(noteByte - 57, LOW);" needs a bit of work
it relies on an exact range of notes to be played
If you play a note lower than 58 you would be trying to access pin 0
So really you would need to put a range filter in place so that it only works with the notes you want it to

  if (noteByte > 56 && noteByte < 61) { // <--use whatever range you need here
      if (commandByte == NoteOn) {
        digitalWrite(noteByte - 57, HIGH);
      }

      if (commandByte == NoteOff) {
        digitalWrite(noteByte - 57, LOW);
      }
  }

it works to put one MIDI note at a time at the moment - but I want to benable to have all five LEDs to light up at the same time as well when I want to.

It will if you send the MIDI to do it. Are you playing a keyboard? If so press the notes down on at a time and hold them until all 5 notes are pressed. You will see all LEDs come on at once. As you remove your fingers from the keyboard one at a time they will go off.
Some keyboards and systems do not send a note off message, but send a note on but with a velocity of zero. The code as it stands can not deal with that.

If you want the LEDs to be on for a fixed amount of time irrespective of when a note off message is received you will have to do it a different way. You implement a state machine where the not on sets a time for the LED to be on. At the start of the loop function you check if any LED needs turning off, and turn it off if needed.