I am trying to make a makey makey arduino basically, The arduino reads the analog ports for the amount of resistance and when it gets below a certain level midi is sent to a converter and then into garage band. I am having trouble with my pitches, right now if either of my analog in puts (0,1) go below the filter then it sends both notes, it should be sending only one note. Note 90 for analog pin 0 and note 91 for analog pin 1.I am stuck I have tried many different ways of making this code and just need some help. Every time I ask for help I am yelled at for not having spaces or too much space etc. This is my first arduino project and Im not the best at making the code pretty yet but I am learning. I would like some guidance on how to fix this thanks!!
#include <MovingAvarageFilter.h>
const int MIDI_ON =144;
const int MIDI_OFF= 128;
const int MIDI_CHANNEL= 0;
MovingAvarageFilter movingAvarageFilter(20);
boolean noteOn [] = {
0, 0};
int inputPins[] = {
0,1};
int INPUT_COUNT = 2;
int pitch [] ={
90,91};
void setup()
{
Serial.begin(115200);
}
void loop() {
for(int i = 0; i < INPUT_COUNT; i++)
{
/*Serial.print("i=");
Serial.println(i);
Serial.print("INPUT_COUNT=");
Serial.println(INPUT_COUNT);
*/
float filtered = movingAvarageFilter.process(analogRead(inputPins[i]));
//Serial.print("filterd=");
//Serial.println(filtered);
if(filtered < 1015 )
{
if(!noteOn[i])
{
//Serial.print ("NOTE ON");
//Serial.println (pitch[i]);
midiSend(MIDI_ON, pitch[i], 100);
noteOn[i] = true;
}
}
if (filtered > 1020)
{
if(noteOn[i])
{
//Serial.print ("NOTE OFF");
//Serial.println (pitch[i]);
midiSend(MIDI_OFF, pitch[i], 100);
noteOn[i] = false ;
}
}
//delay (100);
}
}
void midiSend( int cmd, int data1, int data2 )
{
Serial.write( cmd );
//Serial.write(' ');
Serial.write( data1 );
//Serial.write(' ');
Serial.write( data2 );
//Serial.println();
}