0

I am trying to reverse engineer the project from this video: https://youtu.be/zc1zbwheyE0?t=50s.

From the video a visible 10 wires are going from the LEDs to the Arduino mega, i am assuming that they are wired in a 5x5 matrix (5 rows, 5 columns) given that there are 25 keys on the Midi controller so there most be 25 LEDs.
I reconstructed the project the best a could from observing the video, but my issue is when i press 3 keys 5 LEDs light up unlike in the original video where 3 keys are pressed and 3 LEDs light up(as seen @ 0:50 of the video).
This is the issue i am having : http://imgur.com/a/9SOEJ.
I am thinking the issue is related to how i have my LEDs wired, but my LEDs are wired exactly the same as in the video. isn't it ? is there something i might have missed? How is the project in the video able to light up 3 LEDs without having an issue with extra LEDs lighting up in their matrix? how can i fix my circuit to replicate the video?

Here is some of my coed for turning on an LED when a key is pressed:

<include MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

byte anodes[5] = {30, 32, 34, 36,38};

byte cathodes[5] = {31, 33, 35, 37,39};

byte data1 = 0;

void setPinTo5V(byte pin) //set a pin given to this function to a 5V voltage source

{
    pinMode(pin, OUTPUT);
    digitalWrite(pin, HIGH);
}

void setPinToGND(byte pin) //set a pin given to this function to a GROUND (GND pin)
{
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
}

void loop() {
    MIDI.read();
}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity)
{
    data1 = MIDI.getData1();

    if (data1==48){//C3
        setPinTo5V(anodes[0]);//set pin 30 to 5V
        setPinToGND(cathodes[0]);//set pin 31 to GND

        delay(1); //do nothing for 1 ms
    } //this is done for all 25 keys

}

any help would be appreciated Thanks.

3
  • 1
    duplicate of electronics.stackexchange.com/questions/294435/…
    – CL.
    Mar 24 '17 at 7:53
  • Please edit your question, formatting your code and adding your circuit diagram. Thanks.
    – Mark Smith
    Mar 24 '17 at 7:53
  • Also, break the problem down into parts: if you add some trace (serial.print(...);) into your MyHandleNoteOn() function, you'll be able to tell whether you're detecting too many keys, or lighting too many LEDs.
    – Mark Smith
    Mar 24 '17 at 7:56
1

This was what i was able to come up with, once a notes is press the blink function turns the LED on and off really fast. i am now have trouble getting the led to turn off once the notes is being pressed am not sure if the code is exiting from the while loop.

include

MIDI_CREATE_DEFAULT_INSTANCE();

define LedR 3 //

define LedC 4 //pin for each led

byte data1 = 0;

unsigned long previousMillisR[2]; //[x] = number of leds

unsigned long previousMillisC[2]; //[x] = number of leds

int Status [25];

void setup() {

MIDI.begin(MIDI_CHANNEL_OMNI);

MIDI.setHandleNoteOn(MyHandleNoteOn);

MIDI.setHandleNoteOff(MyHandleNoteOff);

pinMode(LedR, OUTPUT);

pinMode(LedC, OUTPUT);

}

void loop() {

MIDI.read();

//BlinkLedR(LedR,2000, 0); //BlinkLed( which led, interval, one of the stored prevMillis

//BlinkLedC(LedC, 10, 0); //last parameters must be different for each led

}

void BlinkLedR (int led, int interval, int array){

//(long) can be omitted if you dont plan to blink led for very long time I think

if (((long)millis() - previousMillisR[array]) >= interval){

previousMillisR[array]= millis(); //stores the millis value in the 

selected array

digitalWrite(led, !digitalRead(led)); //changes led state

}

}

void BlinkLedC (int led, int interval, int array){

//(long) can be omitted if you dont plan to blink led for very long time I think

if (((long)millis() - previousMillisC[array]) >= interval){

previousMillisC[array]= millis(); //stores the millis value in the 

selected array

digitalWrite(led, !digitalRead(led)); //changes led state

}

}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {

data1 = MIDI.getData1();

if (data1==48){//C3

Status[0]=1;

while(Status[0]==1) {

BlinkLedR(LedR, 10, 0); //BlinkLed( which led, interval, one of the

stored prevMillis

BlinkLedC(LedC, 1, 0); //last parameters must be different for each led

if (Status==!1){

break;

}

}

}

}

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {

data1 = MIDI.getData1();

if (data1==48){//C3

Status[0]=0;

}

}

0

Your code is incomplete, so it's impossible to be sure, but I suspect your problem is with the way you are lighting the LEDs in the matrix.

Think about it conceptually: your LEDs are on the junctions of rows (anodes) and columns (cathodes). To light an LED you make the row high and the column low.

Let's call the rows R1, R2, R3, R4 and R5, and the columsn C1...C5.

Let's say the first LED you want to light is at the junction of R1 and C1. You make R1 high and C1 low.

Now you want to light an LED on the junction of R3 and C3. You make R3 high and C3 low.

What happens? Four lights light up. Why? You have R1 and R3 high, and C1 and C3 low. The circuit doesn't "know" that you want only two LEDs lit: it will light R1C1, R1C3, R3C1 and R3C3.

What is the solution? Remember which LEDs you want lit. Cycle through the matrix and deal with one row at a time: light all the LEDs you want lit in that row. Then move to the next row and repeat. Do this very fast. Your LEDs will be flashing, but if you write your code properly they'll do it so fast you won't be able to see it.

1
  • This was what i was able to come up with, once a notes is press the blink function turns the LED on and off really fast. i am now have trouble getting the led to turn off once the notes is being pressed am not sure if the code is exiting from the while loop.
    – Hjhk90
    Mar 26 '17 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.