Pages: [1]   Go Down
Author Topic: Fix code error  (Read 554 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:


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

Scotland
Offline Offline
Edison Member
*
Karma: 26
Posts: 1340
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need the associated Library and #include

Check where you downloaded it from.
Logged

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

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It stops at this line:-
Code:
   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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-confuse
I think it's posible, but i need some help to get it done smiley

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

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34550
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To send a MIDI message you need to use:-
Code:
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:
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:
noteSend(0x90, note, vol);
and to stop it use:-
Code:
noteSend(0x80, note, 0x00);
or
Code:
noteSend(0x90, note, 0x00);
Where note is the MIDI note number and vol is the volume of that note.
Logged

Pages: [1]   Go Up
Jump to: