Here is my code for my prox synth
#include <SoftwareSerial.h>
byte note = 0; // The MIDI note value to be played
////billy finger vars
int IRpin = A0;
int IRpin2 = A1;
int IRpin3 = A2;
int IRpin4 = A3;
int IRemitter = 5;
//int IRemitter2 = 9;
int ambientIR;
int obstacleIR;
int value[10];
int distance;
int fingers[] = {IRpin,IRpin2,IRpin3,IRpin4};
int lastNotes[] = {0,0,0,0};
int noteMax[] = {0,0,0,0};
int noteMin[] = {1000,1000,1000,1000};
int scaleMajor[] ={2,4,7,9,11};
int minorScale[] = {2,5,8};
///end of billy vars
int pitchbend = 224;
int modwheel = 176;
int lsb = 0;
int msb = 0;
//software serial
SoftwareSerial midiSerial(2, 3); // digital pins that we'll use for soft serial RX & TX
void setup() {
Serial.begin(9600);
midiSerial.begin(31250);
pinMode(IRemitter,OUTPUT);
digitalWrite(IRemitter,LOW);
}
void loop() {
for(int x=0;x<4;x++){//ren though the sensors
int tempVal = 0;
distance = readIR(6,x);
if(distance > noteMax[x]){noteMax[x] = distance;}
if(distance < noteMin[x]){noteMin[x] = distance;}
if((distance > noteMin[x]+1) && (distance < noteMax[x]-1)){
tempVal = ((distance * 127) / (noteMax[x]));
if(x==0){
int temptVal = (((distance - noteMin[x]) * 127) / (noteMax[x] - noteMin[x]));
int adjustVal = tempVal - (tempVal%12);
for(int z=0;z<5;z++){
if (adjustVal = scaleMajor[z]){
tempVal++;
}
}
if(lastNotes[x] != tempVal){
byte tempVal2 = 45;
noteOn(0x90, tempVal, tempVal2);
lastNotes[x] = tempVal;
}
}
if(x==1){
ccSend(19,tempVal);
}
if(x==2){
ccSend(20,tempVal);
}
if(x==3){
int tempVal3 = 127-tempVal;
ccSend(32,tempVal3);// volume!!!!
}
}
Serial.print(x);
Serial.print("(");
Serial.print(noteMax[x]);
Serial.print(":");
Serial.print(tempVal);
Serial.print(":");
Serial.print(noteMin[x]);
Serial.print(") ");
}
Serial.println();
}
void noteOn(byte cmd, byte data1, byte data2) {
midiSerial.write(cmd);
midiSerial.write(data1);
midiSerial.write(data2);
}
void ccSend(byte CCnumber, byte CCdata){
byte CCchannel = 0xB0;
midiSerial.write(CCchannel);
midiSerial.write(CCnumber);
midiSerial.write(CCdata);
}
int readIR(int times,int fingerNum){
for(int x=0;x<times;x++){
digitalWrite(IRemitter,LOW);
delay(1);
ambientIR = analogRead(fingers[fingerNum]);
digitalWrite(IRemitter,HIGH);
delay(1);
obstacleIR = analogRead(fingers[fingerNum]);
value[x] = ambientIR-obstacleIR;
}
distance = 0;
for(int x=0;x<times;x++){
distance +=value[x];
}
return(distance/times);
}
I have the volume working but for the life of me still can't get mod to work?