Help! My Arduino MIDI code is not working, and you all know much more about it than I do. Please help me to fix it! Also, any other suggestions for my code would be helpful. (Not all of this code was written by me. I used some code written by others in my program. I used no copyrighted coding, however.)
I want to use this for a player piano. I know that it is incomplete. I will write more code when I have more capital for parts.
Compiling for Arduino UNO.
Code is attached and below.
Code:
#include <MIDI.h>
#include <ShiftRegister74HC595.h> //Adds Shift register library to Arduino.
int numberOfShiftRegisters = 1; //Sets number of daisychained shift registers.
int serialDataPin = 2; //Sets pin for serial data on the arduino.
int clockPin = 3; //Sets pin for clock signal on the arduino.
int latchPin = 4; //Sets pin for latch pin on the arduino.
int OEPin = 5; //Sets pin for Output Enable control.
int MRPin = 6; //Sets pin for Master Reclear control.
ShiftRegister74HC595 sr (numberOfShiftRegisters,serialDataPin,clockPin,latchPin); //Prepares communication with Shift Register according to settings above.
MIDI_CREATE_DEFAULT_INSTANCE();
void setup(){
pinMode (OEPin, OUTPUT); //Sets Output Enable pin on Arduino to an output.
pinMode (MRPin, OUTPUT); //Sets Master Reclear pin on Arduino to an output.
digitalWrite (OEPin, LOW); //Ties Output Enable pin LOW. Can also provide GND for Shift Register.
digitalWrite (MRPin, HIGH); //Ties Master reclear pin HIGH. Can also provide 5V for Shift Register.
MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to notes on channel 2 only.
MIDI.setHandleNoteOn(HandleNoteOn); // This is important!! This command
// tells the Midi Library which function you want to call when a NOTE ON command
// is received. In this case it's "MyHandleNoteOn".
MIDI.setHandleNoteOff(HandleNoteOff); // This command tells the Midi Library
// to call "MyHandleNoteOff" when a NOTE OFF command is received.
sr.set(0,LOW); //This section sets all notes to their off state.
sr.set(1,LOW);
sr.set(2,LOW);
sr.set(3,LOW);
sr.set(4,LOW);
sr.set(5,LOW);
sr.set(6,LOW);
sr.set(7,LOW);
}
void loop() {
MIDI.read(); // Continuously check if Midi data has been received.
// MyHandleNoteON is the function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void HandleNoteOn(byte channel, byte pitch, byte velocity) {
if (note == 60){
sr.set(0, HIGH);
}
else if (note == 62){
sr.set(1, HIGH);//turn on led
}
else if (note == 64 ){
sr.set(2, HIGH);//turn on led
}
else if (note == 65 ){
sr.set(3, HIGH);//turn on led
}
else if (note == 67 ){
sr.set(4, HIGH);//turn on led
}
else if (note == 69 ){
sr.set(5, HIGH);//turn on led
}
else if (note == 71 ){
sr.set(6, HIGH);//turn on led
}
else if (note == 72 ){
sr.set(7, HIGH);//turn on led
}
// MyHandleNoteOFF is the function that will be called by the Midi Library
// when a MIDI NOTE OFF message is received.
// * A NOTE ON message with Velocity = 0 will be treated as a NOTE OFF message *
// It will be passed bytes for Channel, Pitch, and Velocity
void HandleNoteOff(byte channel, byte pitch, byte velocity) {
if (note == 60){
sr.set(0,LOW);//turn on led
}
else if (note == 62 ){
sr.set(1,LOW);//turn on led
}
else if (note == 64 ){
sr.set(2,LOW);//turn on led
}
else if (note == 65 ){
sr.set(3,LOW);//turn on led
}
else if (note == 67 ){
sr.set(4,LOW);//turn on led
}
else if (note == 69 ){
sr.set(5,LOW);//turn on led
}
else if (note == 71 ){
sr.set(6,LOW);//turn on led
}
else if (note == 72 ){
sr.set(7,LOW);//turn on led
}
}
Error:
C:\Users\Family\Desktop\MIDI_Player_Piano_sketch_1\MIDI_Player_Piano_sketch_1.ino: In function 'void setup()':
MIDI_Player_Piano_sketch_1:20:24: error: 'HandleNoteOn' was not declared in this scope
MIDI.setHandleNoteOn(HandleNoteOn); // This is important!! This command
^
MIDI_Player_Piano_sketch_1:23:25: error: 'HandleNoteOff' was not declared in this scope
MIDI.setHandleNoteOff(HandleNoteOff); // This command tells the Midi Library
^
C:\Users\Family\Desktop\MIDI_Player_Piano_sketch_1\MIDI_Player_Piano_sketch_1.ino: In function 'void loop()':
MIDI_Player_Piano_sketch_1:43:60: error: a function-definition is not allowed here before '{' token
void HandleNoteOn(byte channel, byte pitch, byte velocity) {
^
MIDI_Player_Piano_sketch_1:100:1: error: expected '}' at end of input
}
^
exit status 1
'HandleNoteOn' was not declared in this scope
Thanks for any help you can give me!!!!!
MIDI_Player_Piano_sketch_1.ino (3.78 KB)