Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int velocity = 0x64;
- int baudrate = 31250; //use 9600 for debugging; 31250 is the native baudrate for all MIDI instruments.
- int threshold = 937; //the threshold resistance to trigger sound-earlier
- int noteON = 0x90; //experimentation has indicated that the threshold
- int noteOFF = 129; //is different for USB and DC connections
- int octave = 3;
- int volume = A15;
- int c = 0xC; //define the MIDI value for the note
- int cin = A0; //defines input port
- int cled = 53; //defines LED output port
- int cvalue = 0; //defines the variable for the current of the c photodiode
- int cs = 0xD;
- int csin = A1;
- int csled = 52;
- int csvalue = 0;
- int d = 0xE;
- int din = A2;
- int dled = 51;
- int dvalue = 0;
- int ds = 0xF;
- int dsin = A3;
- int dsled = 50;
- int dsvalue = 0;
- int e = 0x10;
- int ein = A4;
- int eled = 49;
- int evalue = 0;
- int f = 0x11;
- int fin = A5;
- int fled = 48;
- int fvalue = 0;
- int fs = 0x12;
- int fsin = A6;
- int fsled = 47;
- int fsvalue = 0;
- int g = 0x13;
- int gin = A7;
- int gled = 46;
- int gvalue = 0;
- int gs = 0x14;
- int gsin = A8;
- int gsled = 45;
- int gsvalue = 0;
- int a = 0x15;
- int ain = A9;
- int aled = 44;
- int avalue = 0;
- int as = 0x16;
- int ashin = A10;
- int asled = 43;
- int asvalue = 0;
- int b = 0x17;
- int bin = A11;
- int bled = 42;
- int bvalue = 0;
- int co = 0x18;
- int coin = A12;
- int coled = 41;
- int covalue = 0;
- void setup() {
- Serial.begin(baudrate);
- pinMode(cin, INPUT);
- pinMode(csin, INPUT);
- pinMode(din, INPUT);
- pinMode(dsin, INPUT);
- pinMode(ein, INPUT);
- pinMode(fin, INPUT);
- pinMode(fsin, INPUT);
- pinMode(gin, INPUT);
- pinMode(gsin, INPUT);
- pinMode(ain, INPUT);
- pinMode(ashin, INPUT);
- pinMode(bin, INPUT);
- pinMode(coin, INPUT);
- //pinMode(potenpin, INPUT); cancelled feature: octaves. Notes wouldn't turn off :/
- pinMode(cled, OUTPUT);
- pinMode(csled, OUTPUT);
- pinMode(dled, OUTPUT);
- pinMode(dsled, OUTPUT);
- pinMode(eled, OUTPUT);
- pinMode(fled, OUTPUT);
- pinMode(fsled, OUTPUT);
- pinMode(gled, OUTPUT);
- pinMode(gsled, OUTPUT);
- pinMode(aled, OUTPUT);
- pinMode(asled, OUTPUT);
- pinMode(bled, OUTPUT);
- pinMode(coled, OUTPUT);
- }
- void loop() {
- bool cstatus; //defines boolean states. These determine whether or not a note is turned on.
- bool csstatus;
- bool dstatus;
- bool dsstatus;
- bool estatus;
- bool fstatus;
- bool fsstatus;
- bool gstatus;
- bool gsstatus;
- bool astatus;
- bool asstatus;
- bool bstatus;
- bool costatus;
- int atime = 03; //pause for stability and minimizing "ticks" when the harp randomly plays itsself due to variation
- int btime = 03; //in environment light and static
- int cvalue = analogRead(cin);
- int csvalue = analogRead(csin);
- int dvalue = analogRead(din);
- int dsvalue = analogRead(dsin);
- int evalue = analogRead(ein);
- int fvalue = analogRead(fin);
- int fsvalue = analogRead(fsin);
- int gvalue = analogRead(gin);
- int gsvalue = analogRead(gsin);
- int avalue = analogRead(ain);
- int asvalue = analogRead(ashin);
- int bvalue = analogRead(bin);
- int covalue = analogRead(coin);
- if (cvalue > threshold && !cstatus){ //if the current is below the threshold, the light is blocked
- digitalWrite(cled, HIGH); //turn on the corresponding light
- MIDImessage(noteON, c+12*octave, velocity); //play the note
- cstatus = true; //report that the note is on
- delay(atime); //delay for stability
- }
- else if(cvalue > threshold && cstatus){
- delay(atime); //if the note is already on just delay;do not play it again
- }
- else{ //if the threshold is not reached
- digitalWrite(cled, LOW); //turn off the light
- MIDImessage(noteON, c+12*octave, 0x00); //turn the note off(play it with velocity 0)
- cstatus = false; //report that the note is off
- delay(btime); //delay the secondary time
- }
- if (csvalue > threshold && !csstatus){ //same for different note
- digitalWrite(csled, HIGH); //etc
- MIDImessage(noteON, cs+12*octave, velocity);
- csstatus = true;
- delay(atime);
- }
- else if(csvalue > threshold && csstatus){
- delay(atime);
- }
- else{
- digitalWrite(csled, LOW);
- MIDImessage(noteON, cs+12*octave, 0x00);
- csstatus = false;
- delay(btime);
- }
- if (dvalue > threshold+10 && !dstatus){
- digitalWrite(dled, HIGH);
- MIDImessage(noteON, d+12*octave, velocity);
- dstatus = true;
- delay(atime);
- }
- else if (dvalue > threshold+10 && dstatus == 1){
- delay(atime);
- }
- else{
- digitalWrite(dled, LOW);
- MIDImessage(noteON, d+12*octave, 0x00);
- dstatus = false;
- delay(btime);
- }
- if (dsvalue > threshold && !dsstatus){
- digitalWrite(dsled, HIGH);
- MIDImessage(noteON, ds+12*octave, velocity);
- dstatus = true;
- delay(atime);
- }
- else if (dsvalue > threshold && dsstatus){
- delay(atime);
- }
- else{
- digitalWrite(dsled, LOW);
- MIDImessage(noteON, ds+12*octave, 0x00);
- dsstatus = false;
- delay(btime);
- }
- if (evalue > threshold && !estatus){
- digitalWrite(eled, HIGH);
- MIDImessage(noteON, e+12*octave, velocity);
- estatus = true;
- delay(atime);
- }
- else if (evalue > threshold && estatus){
- delay(atime);
- }
- else{
- digitalWrite(eled, LOW);
- MIDImessage(noteON, e+12*octave, 0x00);
- estatus = false;
- delay(btime);
- }
- if (fvalue > threshold && !estatus){
- digitalWrite(fled, HIGH);
- MIDImessage(noteON, f+12*octave, velocity);
- fstatus = true;
- delay(atime);
- }
- else if (fvalue > threshold && fstatus){
- delay(atime);
- }
- else{
- digitalWrite(fled, LOW);
- MIDImessage(noteON, f+12*octave, 0x00);
- fstatus = false;
- delay(btime);
- }
- if (fsvalue > threshold && !fsstatus){
- digitalWrite(fsled, HIGH);
- MIDImessage(noteON, fs+12*octave, velocity);
- fsstatus = true;
- delay(atime);
- }
- else if (fsvalue > threshold && fsstatus){
- delay(atime);
- }
- else{
- digitalWrite(fsled, LOW);
- MIDImessage(noteON, fs+12*octave, 0x00);
- fsstatus = false;
- delay(btime);
- }
- if (gvalue > threshold && !gstatus){
- digitalWrite(gled, HIGH);
- MIDImessage(noteON, g+12*octave, velocity);
- gstatus = true;
- delay(atime);
- }
- else if (gvalue > threshold && gstatus){
- delay(atime);
- }
- else{
- digitalWrite(gled, LOW);
- MIDImessage(noteON, g+12*octave, 0x00);
- gstatus = false;
- delay(btime);
- }
- if (gsvalue > threshold && !gsstatus){
- digitalWrite(gsled, HIGH);
- MIDImessage(noteON, gs+12*octave, velocity);
- gsstatus = true;
- delay(atime);
- }
- else if (gsvalue > threshold && gsstatus){
- delay(atime);
- }
- else{
- digitalWrite(gsled, LOW);
- MIDImessage(noteON, gs+12*octave, 0x00);
- gsstatus = false;
- delay(btime);
- }
- if (avalue > threshold && !astatus){
- digitalWrite(aled, HIGH);
- MIDImessage(noteON, a+12*octave, velocity);
- astatus = true;
- delay(atime);
- }
- else if (avalue > threshold && astatus){
- delay(atime);
- }
- else{
- digitalWrite(aled, LOW);
- MIDImessage(noteON, a+12*octave, 0x00);
- astatus = false;
- delay(btime);
- }
- if (asvalue > threshold && !asstatus){
- digitalWrite(asled, HIGH);
- MIDImessage(noteON, as+12*octave, velocity);
- asstatus = true;
- delay(atime);
- }
- else if (asvalue > threshold && asstatus){
- delay(atime);
- }
- else{
- digitalWrite(asled, LOW);
- MIDImessage(noteON, as+12*octave, 0x00);
- asstatus = false;
- delay(btime);
- }
- if (bvalue > threshold-4 && !bstatus){
- digitalWrite(bled, HIGH);
- MIDImessage(noteON, b+12*octave, velocity);
- bstatus = true;
- delay(atime);
- }
- else if (bvalue > threshold-4 && bstatus){
- delay(atime);
- else{
- digitalWrite(bled, LOW);
- MIDImessage(noteON, b+12*octave, 0x00);
- bstatus = false;
- delay(atime);
- }
- if (covalue > threshold && !costatus){
- digitalWrite(coled, HIGH);
- MIDImessage(noteON, co+12*octave, velocity);
- costatus = true;
- delay(atime);
- }
- else if (covalue > threshold && costatus){
- delay(atime);
- }
- else{
- digitalWrite(coled, LOW);
- MIDImessage(noteON, co+12*octave, 0x00);
- costatus = false;
- delay(atime);
- }
- } //defines function for sending MIDI signals
- void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
- Serial.write(command);//send note on or note off command
- Serial.write(MIDInote);//send pitch data
- Serial.write(MIDIvelocity);//send velocity data
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement