Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are 25 LEDs in a 5x5 matrix (5 rows, 5 columns) connected to a 25 key MIDI controller by way of an Arduino Mega

There are 25 LEDs in a 5x5 matrix (5 rows, 5 columns) connected to a 25 key MIDI controller by way of an Arduino Mega 2560 with a MIDI shield; each led corresponds to one key of the MIDI controller. Below is the code that lights up each LED when a note on the MIDI controller is pressed. When two notes are pressed at the same time notes D3-(colpin3, rowpin1) & F3-(colpin1, rowpin2) light up as well as the LEDs for C3-(colpin1, rowpin1) & G3-(colpin3, rowpin2) even though those notes are not being pressed. When x number of notes are pressed the same number of LEDs should light up. In C++ edit the code so that when two or more notes are pressed at the same time on the MIDI controller, only the LEDs for the notes being pressed light up.

#include MIDI_CREATE_DEFAULT_INSTANCE();

int colpin1=31; int colpin2=33; int colpin3=35; int colpin4=37; int colpin5=39; int rowpin1=30; int rowpin2=32; int rowpin3=34; int rowpin4=36; int rowpin5=38; byte data1 = 0; byte data2 = 0;

void setup() { MIDI.begin(MIDI_CHANNEL_OMNI); MIDI.setHandleNoteOn(MyHandleNoteOn); MIDI.setHandleNoteOff(MyHandleNoteOff); pinMode(colpin1,OUTPUT); pinMode(colpin2,OUTPUT); pinMode(colpin3,OUTPUT); pinMode(colpin4,OUTPUT); pinMode(colpin5,OUTPUT); pinMode(rowpin1,OUTPUT); pinMode(rowpin2,OUTPUT); pinMode(rowpin3,OUTPUT); pinMode(rowpin4,OUTPUT); pinMode(rowpin5,OUTPUT); digitalWrite(colpin1,HIGH); digitalWrite(colpin2,HIGH); digitalWrite(colpin3,HIGH); digitalWrite(colpin4,HIGH); digitalWrite(colpin5,HIGH); digitalWrite (rowpin1,LOW); digitalWrite (rowpin2,LOW); digitalWrite (rowpin3,LOW); digitalWrite (rowpin4,LOW); digitalWrite (rowpin5,LOW); }

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

if (data1==48){//C3 digitalWrite(colpin1,LOW); digitalWrite(rowpin1,HIGH); } if (data1==49){//C3# digitalWrite(colpin2,LOW); digitalWrite(rowpin1,HIGH); } if (data1==50){//D3 digitalWrite(colpin3,LOW); digitalWrite(rowpin1,HIGH); } if (data1==51){//D3# digitalWrite(colpin4,LOW); digitalWrite(rowpin1,HIGH); } if (data1==52){//E3 digitalWrite(colpin5,LOW); digitalWrite(rowpin1,HIGH); } if (data1==53){//F3 digitalWrite(colpin1,LOW); digitalWrite(rowpin2,HIGH); } if (data1==54){//F3# digitalWrite(colpin2,LOW); digitalWrite(rowpin2,HIGH); } if (data1==55){//G3 digitalWrite(colpin3,LOW); digitalWrite(rowpin2,HIGH); } if (data1==56){//G3# digitalWrite(colpin4,LOW); digitalWrite(rowpin2,HIGH); } if (data1==57){//A3 digitalWrite(colpin5,LOW); digitalWrite(rowpin2,HIGH); } if (data1==58){//A3# digitalWrite(colpin1,LOW); digitalWrite(rowpin3,HIGH); } if (data1==59){//B3 digitalWrite(colpin2,LOW); digitalWrite(rowpin3,HIGH); } if (data1==60){//C4 digitalWrite(colpin3,LOW); digitalWrite(rowpin3,HIGH); } if (data1==61){//C4# digitalWrite(colpin4,LOW); digitalWrite(rowpin3,HIGH); } if (data1==62){//D4 digitalWrite(colpin5,LOW); digitalWrite(rowpin3,HIGH); } if (data1==63){//D4# digitalWrite(colpin1,LOW); digitalWrite(rowpin4,HIGH); } if (data1==64){//E4 digitalWrite(colpin2,LOW); digitalWrite(rowpin4,HIGH); } if (data1==65){//F4 digitalWrite(colpin3,LOW); digitalWrite(rowpin4,HIGH); } if (data1==66){//F4# digitalWrite(colpin4,LOW); digitalWrite(rowpin4,HIGH); } if (data1==67){//G4 digitalWrite(colpin5,LOW); digitalWrite(rowpin4,HIGH); } if (data1==68){//G4# digitalWrite(colpin1,LOW); digitalWrite(rowpin5,HIGH); } if (data1==69){//A4 digitalWrite(colpin2,LOW); digitalWrite(rowpin5,HIGH); } if (data1==70){//A4# digitalWrite(colpin3,LOW); digitalWrite(rowpin5,HIGH); } if (data1==71){//B4 digitalWrite(colpin4,LOW); digitalWrite(rowpin5,HIGH); } if (data1==72){//C5 digitalWrite(colpin5,LOW); digitalWrite(rowpin5,HIGH); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions