# Fix code error

**URL:** <https://forum.arduino.cc/t/fix-code-error/101942>\
**Category:** Programming\
**Created:** [May 3, 2012, 9:23pm UTC](https://forum.arduino.cc/t/fix-code-error/101942 "2012-05-03T21:23:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 3, 2012, 9:23pm UTC](https://forum.arduino.cc/t/fix-code-error/101942/1 "2012-05-03T21:23:35Z")

</div>

Hello,

I have a code found on the net, wich i wanted to use as a basic to create my own code for my purpose.  
But i can't get the buggs out. Here is my code. Can please someone tellme what i'm doing wrong?

```cpp
 int ledPin = 13;
 int Basedrum  = 0;
 int Snare = 1;
 int Tom1 = 2;
 int Tom2 = 3;
 int Tom3 = 4;
 int Hihat = 5;
 int Crash = 6;
 int Ride = 7;

byte val = 0;
byte val2 = 0;
byte val3 = 0;
byte val4 = 0;
byte val5 = 0;
byte val6 = 0;
byte val7 = 0;
byte val8 = 0;

int statePin = LOW;
int THRESHOLD = 20;

void setup() {
 pinMode(ledPin, OUTPUT); 
 Serial.begin(115200);
}
  

void loop() 
{
 
  val = analogRead (Basedrum);     
  val2 = analogRead(Snare);
  val3 = analogRead(Tom1);
  val4 = analogRead(Tom2);
  val5 = analogRead(Tom3);
  val6 = analogRead(Hihat);
  val7 = analogRead(Crash);
  val8 = analogRead(Ride);
  
    
  if (val > THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 36, val);
    midi_note_off(0, 36, val);
    delay(100);
  }
  
  if (val2 >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 38, val2);
  midi_note_off(0, 38, val2);
  delay(100);
  }
  
  if (val3 >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 40, val3);
  midi_note_off(0, 40, val3);
  delay(100);
}
  
  
  if (val4 >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 43, val4);
  midi_note_off(0, 43, val4);
  delay(100);
}
  
  if (val5 >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 45, val5);
  midi_note_off(0, 45, val5);
  delay(100);
}

if (val6 >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 47, val6);
  midi_note_off(0, 47, val6);
  delay(100);
}

if (val7 >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 49, val7);
  midi_note_off(0, 49, val7);
  delay(100);
}

if (val8 >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    midi_note_on(0, 51, val8);
  midi_note_off(0, 51, val8);
  delay(100);
}

  
}

```

Thanks a lot!!!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 3, 2012, 9:26pm UTC](https://forum.arduino.cc/t/fix-code-error/101942/2 "2012-05-03T21:26:14Z")

</div>

(deleted)

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [May 3, 2012, 9:27pm UTC](https://forum.arduino.cc/t/fix-code-error/101942/3 "2012-05-03T21:27:47Z")

</div>

It stops at this line:-

```arduino
    midi_note_on(0, 36, val);

```

and says

> sketch\_may03a:47: error: 'midi\_note\_on' was not declared in this scope

That means it has no idea what that function midi\_note\_on is, it is not defined anywhere in the sketch.

Are you missing some sort of library? Or missing the definition of this function.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 7, 2012, 9:12pm UTC](https://forum.arduino.cc/t/fix-code-error/101942/4 "2012-05-07T21:12:29Z")

</div>

Thanks a lot for your help!

How do i " define" midi\_note\_on and Midi\_note\_off ?

I try to understand the language and read examples from other programmers, but i can't find a rule  
that explains me to define that.

Short version of what i want to create actually:  
=== two shoes, each a FSR sensor sending to arduino uno with XBees.

=== On the arduino uno a display with two buttons to controll ( increase or degrease drumpreset like Accoustic and house/techno for example )or a touchscreen with those functions.

=== A Xbees receiver by my drummudule.

Ik know what i want, but i don't have the Knowledge to programming :~  
I think it's posible, but i need some help to get it done 🙂

Who wants to help as a challenge to make my project to work? any help is appreciated!

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [May 7, 2012, 10:01pm UTC](https://forum.arduino.cc/t/fix-code-error/101942/5 "2012-05-07T22:01:15Z")

</div>

To send a MIDI message you need to use:-

```arduino
 void noteSend(int cmd, int data1, int data2) {
  cmd = cmd | midiChannel;  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}

```

Having first set

```arduino
Serial.begin(31250);      // MIDI speed

```

In the setup() and have defined midiChannel as a global variable and set it to what channel you want. Note channel 0 is what MIDI software calls channel 1.

> How do i " define" midi\_note\_on and Midi\_note\_off ?

To play a note use:-

```arduino
noteSend(0x90, note, vol);

```

and to stop it use:-

```arduino
 noteSend(0x80, note, 0x00);

```

or

```arduino
noteSend(0x90, note, 0x00);

```

Where note is the MIDI note number and vol is the volume of that note.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 7:48pm UTC](https://forum.arduino.cc/t/fix-code-error/101942/6 "2021-05-05T19:48:14Z")

</div>

Closed on May 5, 2021, 7:48pm UTC


