#include <LiquidCrystal.h>
#define NOTE_ON 144
#define CONTROLCHANGE 176
#define ALLSOUNDOFF 120
#define SensorsNumber 6 //number of photo sensor
#define Legato 10
#define Limit 710
const int RightSW=13, LeftSW=10, ToggleDown=12, ToggleUp=11;
int Input[SensorsNumber] = {0,1,2,4,5,3};
int Note[SensorsNumber] = {nRT,nRM,nRB,nLT,nLM,nLB};
short Counter[Sensorsnumber]; //change to int
void sendMidi(int cmd, int pitch, int velocity);
//LB=LeftBottom(pin3),LM=LeftMiddle(pin5),LT=LeftTop(pin4),RB=RightBottom(pin2),RM=RightMiddle(pin1),RT=RightTop(pin0)
void sendMidi(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
int Evaluate(int Pin){
int Status = 0;
//thanks to developer who establish this function:https://jumbleat.com/2016/12/01/revision_of_avoiding_chatter/
if(1000 < analogRead(Input[Pin])){
Counter[Pin]++; //increase number
if(Counter[Pin] > Limit){ //when count get limitance
Counter[Pin] = Limit;
}
}else{
if(Counter[Pin] > Legato){
Status = 3; //stop shading
}
Counter[Pin] = 0;
}
if(Counter[Pin] > Legato){
Status = 2; //while shading
}
else if(Counter[Pin] == Legato){
Status = 1; //start shading
}
return Status;
}
Serial.begin(31250);
pinMode(RightSW,INPUT); //now developing laser harp systems with switches
pinMode(LeftSW,INPUT);
pinMode(ToggleDown,INPUT);
pinMode(ToggleUp,INPUT);
sendMidi(CONTROLCHANGE, ALLSOUNDOFF, 0);
}
void loop(){
for(int n = 0; n < SensorsNumber; n++){
int Status = Evaluate(n);
if(Status == 1){
sendMidi(NOTE_ON, Note[n], Velocity[n]);
}
else if(Status == 3){
sendMidi(NOTE_ON, Note[n], 0); //velocity 0 means note off
}
}
}