Go Down

Topic: AnalogRead peak detection (local maxima) (Read 3 times) previous topic - next topic

qwertygin

#5
May 06, 2011, 12:16 pm Last Edit: May 06, 2011, 12:57 pm by qwertygin Reason: 1
Well,my protoshield is finished although it looks very sorry 'cause of my horrific soldering but it works!
included 6 leds to flash on hit.

now i'm converting the sketch to send Midi note messages like this :
Code: [Select]
#include <Compatibility_v2.5.h>
#include <MIDI.h>

int Threshold = 200;
int velocity;
int Hit;

int PadNote1 = 35;
int PadNote2 = 38;
int PadNote3 = 41;
int PadNote4 = 43;
int PadNote5 = 46;
int PadNote6 = 49;

void setup(){
  for (int i = 2;i<=7;i++){
    pinMode (i,OUTPUT);
  }
  pinMode (13,OUTPUT);
  BlinkLed (3,500);
  Serial.begin(38400);

}

void loop(){
  for (int i = 0;i<=5;i++){                //Cycle through ADC channels.
    if (analogRead(i)>Threshold){          //If current channel reading exceeds threshold
      Hit = AnalogMaxima (i,Threshold,2);  //find local maxima and return value.
      if (Hit == 1025 || Hit == 0){        //if still ascending or below threshold,
        break;                             //go to next ADC channel.
      }
      else{
        velocity = map(Hit,Threshold,1000,0,127);
       
        if (i==0){
        MIDI.sendNoteOn(PadNote1,velocity,10);
        MIDI.sendNoteOff(PadNote1,0,10);
        }
        if (i==1){
        MIDI.sendNoteOn(PadNote2,velocity,10);
        MIDI.sendNoteOff(PadNote2,0,10);
        }
        if (i==2){
        MIDI.sendNoteOn(PadNote3,velocity,10);
        MIDI.sendNoteOff(PadNote3,0,10);
        }
        if (i==3){
        MIDI.sendNoteOn(PadNote4,velocity,10);
        MIDI.sendNoteOff(PadNote4,0,10);
        }
        if (i==4){
        MIDI.sendNoteOn(PadNote5,velocity,10);
        MIDI.sendNoteOff(PadNote5,0,10);
        }
        if (i==5){
        MIDI.sendNoteOn(PadNote6,velocity,10);
        MIDI.sendNoteOff(PadNote6,0,10);
        }
       
 
        digitalWrite(i+2,HIGH);
        delay(7);
        digitalWrite(i+2,LOW);
       
      }
    }
  }
}

etc....


I really dislike using those 6 if's though...
could someone show me how to do it like this:
Code: [Select]
MIDI.sendNoteOn(PadNote'i',velocity,10);
i only need the syntax to use the i integer in conjunction with a prefix ('PadNote' in this instance for PadNote1...6)

i did not post the complete sketch,just enough to ask...

If shit didn't happen..
..you would explode..

Msquare


qwertygin

If shit didn't happen..
..you would explode..

Go Up