Compile not working - Desperate

I need this code done within the next hour and I can’t figure out the problem (I’m not very experienced and I recieved help on it from someone else)
It is for a MIDI keyboard.

Here is the code:

const byte keyPints = { 15,16,17,18,19,13,13,11,10,9,8,7,6,5,4,3,2};
const byte notes = {0,2,4,5,6,9,11,12,14,16,17,19,21,23,23,24,26,28,29,31,33,35,36,38,40,41,43,45,47,48};
const int keyThreshold = {85, 255, 426, 596, 767, 937, 1024};
const int musicKeyPin = A0; //key select alligator clip input pin
const int numberOfKeys = 17;
boolean keyUp[numberOfKeys];
byte channel = 0; //MIDI channel to send data on
byte octave = 3; //two below Middle C
byte lookUpOffset, keyOffset, playingKey;

void setup(){
Serial.begin(31250); //MIDI baud rate
for(int i=0; i<numberOfKeys; i++){
pinMode(keyPins*, INPUT_PULLUP);*
_ keyUp = true;_
* }*
* playingKey = findKey(); // 1 to 7 is A to G*
* keyOffset = notes[playingKey];*
_ lookUpOffset = 7+ (octave * 12);_
* // setup voice to use*
* controlSend(0, 0, channel); // set bank 0 MSB*
* controlSend(32, 0, channel); // set bank 0 LSB*
* programChange(19); // send voice number - Church Organ*
}

void loop(){
* boolean key;*
* for(int i=0; i<numberOfKeys; i++){*
_ key = digitalRead(keyPin*);
if(key != keyUp){ //change in key state*

if(keyUp*) {
midiSend(0x90, lookUpNote(i), 127; //note on*

* }
else {
midiSend(0x80, lookUpNote(i), 0; //note off*

* }
keyUp = key;
}
}
}
void midiSend(byte cmd, byte d1, byte d2){
cmd = cmd | channel;
Serial.write(cmd);
Serial.write(d1);
Serial.write(d2);
}
byte lookUpNote(int i){
byte note;
note = notes + lookUpOffset + keyOffset;
return note;
}
byte findKey(){ //look up what key we are in
int i = 0;
int clipVoltage = analogRead(musicKeyPin);
while(keyThreshhold < clipVoltage) i++;
i++;
return (byte) i;
}
void controlSend(byte CCnumber, byte CCdata, byte CCchannel) {
CCchannel |= 0xB0; //convert to Controller message*

* Serial.write(CCchannel);
Serial.write(CCnumber);
Serial.write(CCdata);
}
void programChange(byte voice){
Serial.write((byte)0xC0 | channel);
Serial.write(voice;
}
And here is the error:
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\g\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10801 -build-path C:\Users\Scot\AppData\Local\Temp\arduino_build_508271 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\g\Documents\Arduino\ActualMIDIfinal\ActualMIDIfinal.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Scot\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10801 -build-path C:\Users\Scot\AppData\Local\Temp\arduino_build_508271 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Scot\Documents\Arduino\ActualMIDIfinal\ActualMIDIfinal.ino
Using board ‘uno’ from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core ‘arduino’ from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used…_

“C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard” “C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp” -o “nul”
Generating function prototypes…
“C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard” “C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp” -o “C:\Users\g\AppData\Local\Temp\arduino_build_508271\preproc\ctags_target_for_gcc_minus_e.cpp”
“C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags” -u --language-force=c++ -f - --c+±kinds=svpf --fields=KSTtzns --line-directives “C:\Users\Scot\AppData\Local\Temp\arduino_build_508271\preproc\ctags_target_for_gcc_minus_e.cpp”
Compiling sketch…
“C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++” -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR “-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino” “-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard” “C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp” -o “C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp.o”
C:\Users\g\Documents\Arduino\ActualMIDIfinal\ActualMIDIfinal.ino: In function ‘void loop()’:
ActualMIDIfinal:23: error: a function-definition is not allowed here before ‘{’ token
void setup(){
_ ^
ActualMIDIfinal:85: error: expected ‘}’ at end of input
}
^*

exit status 1
a function-definition is not allowed here before ‘{’ token
If you could help in fixing this error, along with any other errors that might be there, since it hasn’t gone through all the way, being stopped at that error way at the top of the code.
Also, I hate to be any bit rude, but I’d really like it if I could just get straight up help and not answers like I should learn C and C++ myself first, it will be a life long lesson and it will pay off, and I shouldn’t be asking for help cause I’m so inexperienced (sorry, that’s just what I’ve gotten in past posts from a long time ago when I really needed straight up help). I have learning it on my to do list, but I’m really tight on time. Any straight up edits and help would be greatly appreciated_

Take a look at the code you posted. Do you see how a little ways in some of it is missing and the text turns to italics after that? That’s because the forum interpreted some of the code as forum markup. This is why we have the rule here that all code, warning, and error messages must be posted using code tags.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Exo78:

const byte keyPints[] = { 15,16,17,18,19,13,13,11,10,9,8,7,6,5,4,3,2};

should be:

const byte keyPins[] = { 15,16,17,18,19,13,13,11,10,9,8,7,6,5,4,3,2};

Exo78:

    key = digitalRead(keyPin[i]);

should be:

   key = digitalRead(keyPins[i]);

Exo78:

  Serial.write(voice;

should be:

 Serial.write(voice);

Exo78:

      midiSend(0x90, lookUpNote(i), 127; //note on

should be

     midiSend(0x90, lookUpNote(i), 127); //note on

Exo78:

      midiSend(0x80, lookUpNote(i), 0; //note off

should be

     midiSend(0x80, lookUpNote(i), 0); //note off

Exo78:

  while(keyThreshhold[i] < clipVoltage) i++;

should be

 while(keyThreshold[i] < clipVoltage) i++;

Really almost every one of these is so simple to fix. Just take a second to read the highlighted line when there’s an error and your mistake is obvious. In the time it took you to make this post on the forum you could have done that.

Please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

It seems to me that the code you posted is not the same as the code that gave the error because the posted code gives other errors that look like transcription typos.

…R
PS. @pert got there first.

const byte keyPints[] = { 15,16,17,18,19,13,13,11,10,9,8,7,6,5,4,3,2};
const byte notes[] = {0,2,4,5,6,9,11,12,14,16,17,19,21,23,23,24,26,28,29,31,33,35,36,38,40,41,43,45,47,48};
const int keyThreshold[] = {85, 255, 426, 596, 767, 937, 1024};
const int musicKeyPin = A0; //key select alligator clip input pin
const int numberOfKeys = 17;
boolean keyUp[numberOfKeys];
byte channel = 0; //MIDI channel to send data on
byte octave = 3; //two below Middle C
byte lookUpOffset, keyOffset, playingKey;

void setup(){
  Serial.begin(31250); //MIDI baud rate
  for(int i=0; i<numberOfKeys; i++){
    pinMode(keyPins, INPUT_PULLUP);
    keyUp = true;
  }
  playingKey = findKey(); // 1 to 7 is A to G
  keyOffset = notes[playingKey];
  lookUpOffset = 7+ (octave * 12);
  // setup voice to use
  controlSend(0, 0, channel); // set bank 0 MSB
  controlSend(32, 0, channel); // set bank 0 LSB
  programChange(19); // send voice number - Church Organ
 }
 
void loop(){
  boolean key;
  for(int i=0; i<numberOfKeys; i++){
    key = digitalRead(keyPin);
    if(key != keyUp){ //change in key state
      if(keyUp) {
      midiSend(0x90, lookUpNote(i), 127; //note on
         }
      else {
      midiSend(0x80, lookUpNote(i), 0; //note off
      }
      keyUp = key;
    }
  }
}
void midiSend(byte cmd, byte d1, byte d2){
  cmd = cmd | channel;
  Serial.write(cmd);
  Serial.write(d1);
  Serial.write(d2);
}

byte lookUpNote(int i){
  byte note;
  note = notes + lookUpOffset + keyOffset;
  return note;
}

byte findKey(){ //look up what key we are in
  int i = 0;
  int clipVoltage = analogRead(musicKeyPin);
  while(keyThreshhold < clipVoltage) i++;
  i++;
  return (byte) i;
}

void controlSend(byte CCnumber, byte CCdata, byte CCchannel) {
  CCchannel |= 0xB0; //convert to Controller message
  Serial.write(CCchannel);
  Serial.write(CCnumber);
  Serial.write(CCdata);
}

void programChange(byte voice){
  Serial.write((byte)0xC0 | channel);
  Serial.write(voice;
}

Error:

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\g\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10801 -build-path C:\Users\g\AppData\Local\Temp\arduino_build_508271 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\g\Documents\Arduino\ActualMIDIfinal\ActualMIDIfinal.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\g\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10801 -build-path C:\Users\g\AppData\Local\Temp\arduino_build_508271 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\g\Documents\Arduino\ActualMIDIfinal\ActualMIDIfinal.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp" -o "nul"
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp" -o "C:\Users\g\AppData\Local\Temp\arduino_build_508271\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\g\AppData\Local\Temp\arduino_build_508271\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp" -o "C:\Users\g\AppData\Local\Temp\arduino_build_508271\sketch\ActualMIDIfinal.ino.cpp.o"
C:\Users\g\Documents\Arduino\ActualMIDIfinal\ActualMIDIfinal.ino: In function 'void loop()':

ActualMIDIfinal:23: error: a function-definition is not allowed here before '{' token

 void setup(){

             ^

ActualMIDIfinal:85: error: expected '}' at end of input

 }

 ^

exit status 1
a function-definition is not allowed here before '{' token

Sorry for the confusion with this. Like I said before, I have little to no knowledge in C or C++, and I had a lot of help with this from another source. I understand to a full extent that I’m a complete noob at all of this, and that these errors are most likely due to simple syntax or something easy like that. When I try to upload the code to my uno with a midi shield on top, that error stops the compiling and uploading process. I’m wondering if I could be provided with corrections to that error and any others that would prevent the code from being compiled and uploaded to my uno. Again, I appreciate responses.

Exo78:
I'm wondering if I could be provided with corrections to that error and any others that would prevent the code from being compiled and uploaded to my uno. Again, I appreciate responses.

I took the time to provide several corrections and you didn't even make the effort to fix those things in your code.

Hey you have missed the comments off the top of that code it should say:-

/* MIDI Spoon-o-phone - Mike Cook
* simple pull down inputs for piano keys * Alligator clip defines the key
*/

Bad form not acknowledging the author, especially bad when you cut it out altogether, even worst when it is me!

To correct the errors then type in what was in the book exactly.

Grumpy_Mike:
Bad form not acknowledging the author, especially bad when you cut it out altogether, even worst when it is me!

To correct the errors then type in what was in the book exactly.

LOL

Alternatively ...
Please fix the car I stole from your showroom last week before I learned to drive.

...R

Grumpy_Mike:
Hey you have missed the comments off the top of that code it should say:-

/* MIDI Spoon-o-phone - Mike Cook
  • simple pull down inputs for piano keys * Alligator clip defines the key
    */



Bad form not acknowledging the author, especially bad when you cut it out altogether, even worst when it is me!

To correct the errors then type in what was in the book exactly.

I think Grumpy Mike comprehensively now owns this thread. :smiley:

Thread locked.