Go Down

Topic: Fix code error (Read 613 times) previous topic - next topic

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?

Code: [Select]



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!!!

spycatcher2k

You need the associated Library and #include

Check where you downloaded it from.
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Grumpy_Mike

It stops at this line:-
Code: [Select]
   midi_note_on(0, 36, val);
and says
Quote
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.

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!

Grumpy_Mike

To send a MIDI message you need to use:-
Code: [Select]
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
Code: [Select]
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.

Quote
How do i " define"  midi_note_on and Midi_note_off ?

To play a note use:-
Code: [Select]
noteSend(0x90, note, vol);
and to stop it use:-
Code: [Select]
noteSend(0x80, note, 0x00);
or
Code: [Select]
noteSend(0x90, note, 0x00);
Where note is the MIDI note number and vol is the volume of that note.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy