diff --git a/sketches/max_sketch/7_Socket_KeyboardTEST/Socket_KeyboardTEST.ino b/sketches/max_sketch/7_Socket_KeyboardTEST/Socket_KeyboardTEST.ino new file mode 100644 index 0000000..cae65ed --- /dev/null +++ b/sketches/max_sketch/7_Socket_KeyboardTEST/Socket_KeyboardTEST.ino @@ -0,0 +1,56 @@ +int A; +int B; +int C; + +bool BA; +bool BB; +bool BC; + +void setup() { +Serial.begin(9600); +} + +void loop() { + +A = analogRead (A1); +Serial.print ("A="); +Serial.println (A); +B = analogRead (A2); +Serial.print ("B="); +Serial.println (B); +C = analogRead (A3); +Serial.print ("C="); +Serial.println (C); + + +if (A>100 && !BA) { + tone(9, 200); + BA = true; + } + + else if (A<100 && BA){ + noTone(9); + BA = false; + } + + + if (B>100 && !BB) { + tone(9, 400); + BB = true; + } + + else if (B<100 && BB){ + noTone(9); + BB = false; + } + if (C>100 && !BC) { + tone(9, 600); + BC = true; + } + + else if (C<100 && BC){ + noTone(9); + BC = false; + } + +} diff --git a/sketches/max_sketch/8_Poly_Mplx_2_smplfd/Poly_Mplx_2_smplfd.ino b/sketches/max_sketch/8_Poly_Mplx_2_smplfd/Poly_Mplx_2_smplfd.ino new file mode 100644 index 0000000..43a9acf --- /dev/null +++ b/sketches/max_sketch/8_Poly_Mplx_2_smplfd/Poly_Mplx_2_smplfd.ino @@ -0,0 +1,194 @@ +#include +#include + + + +#include +#include +#include +//#include +//#include + +#define CONTROL_RATE 128 // powers of 2 please + +Oscil tone_1(SAW256_DATA); +Oscil tone_2(SAW256_DATA); +Oscil tone_3(SAW256_DATA); +Oscil tone_4(SAW256_DATA); +Oscil tone_5(SAW256_DATA); +Oscil tone_6(SAW256_DATA); +Oscil tone_7(SAW256_DATA); +Oscil tone_8(SAW256_DATA); +Oscil tone_9(SAW256_DATA); +Oscil tone_10(SAW256_DATA); +Oscil tone_11(SAW256_DATA); +Oscil tone_12(SAW256_DATA); + +//multiplex adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + +int count= 0; +int TH; +int16_t adc0a, adc1a, adc2a, adc3a, adc0b, adc1b, adc2b, adc3b, adc0c, adc1c, adc2c, adc3c, adc0d, adc1d, adc2d, adc3d; +boolean note1 = false; +boolean note2 = false; +boolean note3 = false; +boolean codeswitch = false; + + +void setup(){ + //set the gain for multiplexed ins + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + //start the multiplexing + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + + startMozzi(CONTROL_RATE); + + //set tone frequency and phase + tone_1.setFreq(165); + tone_1.setPhase(0); + tone_2.setFreq(196); + tone_2.setPhase(30); + tone_3.setFreq(220); + tone_3.setPhase(60); + tone_4.setFreq(262); + tone_4.setPhase(90); + tone_5.setFreq(330); + tone_5.setPhase(120); + tone_6.setFreq(392); + tone_6.setPhase(150); + tone_7.setFreq(440); + tone_7.setPhase(180); + tone_8.setFreq(523); + tone_8.setPhase(210); + tone_9.setFreq(659); + tone_9.setPhase(240); + tone_10.setFreq(784); + tone_10.setPhase(270); + tone_11.setFreq(880); + tone_11.setPhase(300); + tone_12.setFreq(1047); + tone_12.setPhase(330); + + //calibrate (set treshold) + TH = adsb.readADC_SingleEnded(3); +} + +void updateControl(){ + //log number of notes playing + if (adc0a < TH) { + count++; + } + if (adc1a < TH) { + count++; + } + if (adc2a < TH) { + count++; + } + if (adc3a < TH) { + count++; + } + if (adc0b < TH) { + count++; + } + if (adc1b < TH) { + count++; + } + if (adc2b < TH) { + count++; + } + if (adc3b < TH) { + count++; + } + if (adc0c < TH) { + count++; + } + if (adc1c < TH) { + count++; + } + if (adc2c < TH) { + count++; + } + if (adc3c < TH) { + count++; + } +} + + +int updateAudio(){ + int result = 0; + + //Play notes and mix down (according to notes playing + if (adc0a < TH) { + result += tone_1.next() * (1/count); + } + if (adc1a < TH) { + result += tone_2.next() * (1/count); + } + if (adc2a < TH) { + result += tone_3.next() * (1/count); + } + if (adc3a < TH) { + result += tone_4.next() * (1/count); + } + if (adc0b < TH) { + result += tone_5.next() * (1/count); + } + if (adc1b < TH) { + result += tone_6.next() * (1/count); + } + if (adc2b < TH) { + result += tone_7.next() * (1/count); + } + if (adc3b < TH) { + result += tone_8.next() * (1/count); + } + if (adc0c < TH) { + result += tone_9.next() * (1/count); + } + if (adc1c < TH) { + result += tone_10.next() * (1/count); + } + if (adc2c < TH) { + result += tone_11.next() * (1/count); + } + if (adc3c < TH) { + result += tone_12.next() * (1/count); + } + return result; +} + +void loop(){ + //Messure LDR multiplex inputs + adc0a = adsa.readADC_SingleEnded(0); + adc1a = adsa.readADC_SingleEnded(1); + adc2a = adsa.readADC_SingleEnded(2); + adc3a = adsa.readADC_SingleEnded(3); + + adc0b = adsb.readADC_SingleEnded(0); + adc1b = adsb.readADC_SingleEnded(1); + adc2b = adsb.readADC_SingleEnded(2); + adc3b = adsb.readADC_SingleEnded(3); + + adc0c = adsc.readADC_SingleEnded(0); + adc1c = adsc.readADC_SingleEnded(1); + adc2c = adsc.readADC_SingleEnded(2); + adc3c = adsc.readADC_SingleEnded(3); + + adc0d = adsd.readADC_SingleEnded(0); + adc1d = adsd.readADC_SingleEnded(1); + adc2d = adsd.readADC_SingleEnded(2); + adc3d = adsd.readADC_SingleEnded(3); + + audioHook(); +} diff --git a/sketches/max_sketch/Musicwithoutgluten6.1/Musicwithoutgluten6.1.ino b/sketches/max_sketch/Musicwithoutgluten6.1/Musicwithoutgluten6.1.ino new file mode 100644 index 0000000..6216727 --- /dev/null +++ b/sketches/max_sketch/Musicwithoutgluten6.1/Musicwithoutgluten6.1.ino @@ -0,0 +1,504 @@ +#include + +#include +#include +#include + + +//note values +const char note1[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note5[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note6[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note7[] PROGMEM = ":d=128,b=300:f+"; //plays f5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:b+"; //plays b5 + +//instruments +MusicWithoutDelay myI(note1); +MusicWithoutDelay myIn(note2); +MusicWithoutDelay myIns(note3); +MusicWithoutDelay myInst(note4); +MusicWithoutDelay myInstr(note5); +MusicWithoutDelay myInstru(note6); +MusicWithoutDelay myInstrum(note7); +MusicWithoutDelay myInstrume(note8); +MusicWithoutDelay myInstrumen(note9); +MusicWithoutDelay myInstrument(note10); + + + + +int count; +//int vol; +//int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9; +bool CV; + +//bool BA; +//bool BB; +//bool BC; +//bool BD; +//bool BE; +//bool BF; +//bool BG; +//bool BH; +//bool BI; +//bool BJ; + +SensorToButton button0(TH0, pressUp, 50); +SensorToButton button1(TH1, pressUp, 50); +SensorToButton button2(TH2, pressUp, 50); +SensorToButton button3(TH3, pressUp, 50); +SensorToButton button4(TH4, pressUp, 50); +SensorToButton button5(TH5, pressUp, 50); +SensorToButton button6(TH6, pressUp, 50); +SensorToButton button7(TH7, pressUp, 50); +SensorToButton button8(TH8, pressUp, 50); +SensorToButton button9(TH9, pressUp, 50); + +void setup() { + Serial.begin(9600); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (analogRead(A0)+20); + TH1 = (analogRead(A1)+20); + TH2 = (analogRead(A2)+20); + TH3 = (analogRead(A3)+20); + TH4 = (analogRead(A4)+20); + TH5 = (analogRead(A5)+20); + TH6 = (analogRead(A6)+20); + TH7 = (analogRead(A7)+20); + TH8 = (analogRead(A8)+20); + TH9 = (analogRead(A9)+20); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + myI.begin(CHA, SINE, ENVELOPE0, 0); + myIn.begin(SINE, ENVELOPE0, 0); + myIns.begin(SINE, ENVELOPE0, 0); + myInst.begin(SINE, ENVELOPE0, 0); + myInstr.begin(SINE, ENVELOPE0, 0); + myInstru.begin(SINE, ENVELOPE0, 0); + myInstrum.begin(SINE, ENVELOPE0, 0); + myInstrume.begin(SINE, ENVELOPE0, 0); + myInstrumen.begin(SINE, ENVELOPE0, 0); + myInstrument.begin(SINE, ENVELOPE0, 0); + + myI.pause(true); + myIn.pause(true); + myIns.pause(true); + myInst.pause(true); + myInstr.pause(true); + myInstru.pause(true); + myInstrum.pause(true); + myInstrume.pause(true); + myInstrumen.pause(true); + myInstrument.pause(true); + + Serial.println("go!"); +} + +void loop() { + CV = digitalRead(22); + count = 0; + + button0.read (A0); + button1.read (A1); + button2.read (A2); + button3.read (A3); + button4.read (A4); + button5.read (A5); + button6.read (A6); + button7.read (A7); + button8.read (A8); + button9.read (A9); + + myI.update(); + myIn.update(); + myIns.update(); + myInst.update(); + myInstr.update(); + myInstru.update(); + myInstrum.update(); + myInstrume.update(); + myInstrumen.update(); + myInstrument.update(); + + + + //Messure LDR inputs +// VA0 = analogRead(A0); +// VA1 = analogRead(A1); +// VA2 = analogRead(A2); +// VA3 = analogRead(A3); +// +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + +// VA4 = analogRead(A4); +// VA5 = analogRead(A5); +// VA6 = analogRead(A6); +// VA7 = analogRead(A7); +// +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + +// VA8 = analogRead(A8); +// VA9 = analogRead(A9); +// +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.println(" "); + + + if (button0.isPressed()) { + count++; + } + if (button1.isPressed()) { + count++; + } + if (button2.isPressed()) { + count++; + } + if (button3.isPressed()) { + count++; + } + if (button4.isPressed()) { + count++; + } + if (button5.isPressed()) { + count++; + } + if (button6.isPressed()) { + count++; + } + if (button7.isPressed()) { + count++; + } + if (button8.isPressed()) { + count++; + } + if (button9.isPressed()) { + count++; + } + + Serial.print("Intruments playing = "); + Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (button0.isPressed()) { + //vol = 100/count + 25; + myI.play(true); +// myI.setVolume(vol); + VOL0 = constrain(map(analogRead(A0), TH0, 500, 30, 127), 30, 127); + //myI.setMod(VOL0); + myI.setVolume(VOL0); +// BA == true; + Serial.print("Tone1 active at vol:"); + Serial.println(VOL0); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(23, HIGH); + } + else if(!CV) { + digitalWrite(23, LOW); + } + } + + if(button0.wasReleased()){ + myI.pause (true); +// BA == false; + + //Kill ControlVoltage + digitalWrite(23, LOW); + } + + if (button1.isPressed()) { +// vol = 100/count + 25; + myIn.play(true); +// myIn.setVolume(vol); + VOL1 = constrain(map(analogRead(A1), TH1, 500, 30, 127), 30, 127); + //myIn.setMod(VOL1); + myIn.setVolume(VOL1); +// BB == true; + Serial.print("Tone2 active at vol:"); + Serial.println(VOL1); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(25, HIGH); + } + else if(!CV) { + digitalWrite(25, LOW); + } + } + + if(button1.wasReleased()){ + myIn.pause (true); +// BB == false; + + //Kill ControlVoltage + digitalWrite(25, LOW); + } + + if (button2.isPressed()) { +// vol = 100/count + 25; + myIns.play(true); +// myIns.setVolume(vol); + VOL2 = constrain(map(analogRead(A2), TH2, 500, 30, 127), 30, 127); + //myIns.setMod(VOL2); + myIns.setVolume(VOL2); +// BC == true; + Serial.print("Tone3 active at vol:"); + Serial.println(VOL2); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(27, HIGH); + } + else if(!CV) { + digitalWrite(27, LOW); + } + } + + if(button2.wasReleased()){ + myIns.pause (true); +// BC == false; + + //Kill ControlVoltage + digitalWrite(27, LOW); + } + + if (button3.isPressed()) { +// vol = 100/count + 25; + myInst.play(true); +// myInst.setVolume(vol); + VOL3 = constrain(map(analogRead(A3), TH3, 500, 30, 127), 30, 127); + //myInst.setMod(VOL3); + myInst.setVolume(VOL3); +// BD == true; + Serial.print("Tone4 active at vol:"); + Serial.println(VOL3); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(29, HIGH); + } + else if(!CV) { + digitalWrite(29, LOW); + } + } + + if(button3.wasReleased()){ + myInst.pause (true); +// BD == false; + + //Kill ControlVoltage + digitalWrite(29, LOW); + } + + if (button4.isPressed()) { +// vol = 100/count + 25; + myInstr.play(true); +// myInstr.setVolume(vol); + VOL4 = constrain(map(analogRead(A4), TH4, 500, 30, 127), 30, 127); + //myInstr.setMod(VOL4); + myInstr.setVolume(VOL4); +// BE == true; + Serial.print("Tone5 active at vol:"); + Serial.println(VOL4); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(31, HIGH); + } + else if(!CV) { + digitalWrite(31, LOW); + } + } + + if(button4.wasReleased()){ + myInstr.pause (true); +// BE == false; + + //Kill ControlVoltage + digitalWrite(31, LOW); + } + + if (button5.isPressed()) { +// vol = 100/count + 25; + myInstru.play(true); +// myInstru.setVolume(vol); + VOL5 = constrain(map(analogRead(A5), TH5, 500, 30, 127), 30, 127); + //myInstru.setMod(VOL5); + myInstru.setVolume(VOL5); +// BF == true; + Serial.print("Tone6 active at vol:"); + Serial.println(VOL5); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(33, HIGH); + } + else if(!CV) { + digitalWrite(33, LOW); + } + } + + if(button5.wasReleased()){ + myInstru.pause (true); +// BF == false; + + //Kill ControlVoltage + digitalWrite(33, LOW); + } + + + if (button6.isPressed()) { +// vol = 100/count + 25; + myInstrum.play(true); +// myInstrum.setVolume(vol); + VOL6 = constrain(map(analogRead(A6), TH6, 500, 30, 127),30, 127); + //myInstrum.setMod(VOL6); + myInstrum.setVolume(VOL6); +// BG == true; + Serial.print("Tone7 active at vol:"); + Serial.println(VOL6); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(35, HIGH); + } + else if(!CV) { + digitalWrite(35, LOW); + } + } + + if(button6.wasReleased()){ + myInstrum.pause (true); +// BG == false; + + //Kill ControlVoltage + digitalWrite(35, LOW); + } + + if (button7.isPressed()) { +// vol = 100/count + 25; + myInstrume.play(true); +// myInstrume.setVolume(vol); + VOL7 = constrain(map(analogRead(A7), TH7, 500, 30, 127), 30, 127); + //myInstrume.setMod(VOL7); + myInstrume.setVolume(VOL7); +// BH == true; + Serial.print("Tone8 active at vol:"); + Serial.println(VOL7); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(37, HIGH); + } + else if(!CV) { + digitalWrite(37, LOW); + } + } + + if(button7.wasReleased()){ + myInstrume.pause (true); +// BH == false; + + //Kill ControlVoltage + digitalWrite(37, LOW); + } + + + if (button8.isPressed()) { +// vol = 100/count + 25; + myInstrumen.play(true); +// myInstrumen.setVolume(vol); + VOL8 = constrain(map(analogRead(A8), TH8, 500, 30, 127), 30, 127); + //myInstrumen.setMod(VOL8); + myInstrumen.setVolume(VOL8); +// BI == true; + Serial.print("Tone9 active at vol:"); + Serial.println(VOL8); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(39, HIGH); + } + else if(!CV) { + digitalWrite(39, LOW); + } + } + + if(button8.wasReleased()){ + myInstrumen.pause (true); +// BI == false; + + //Kill ControlVoltage + digitalWrite(39, LOW); + } + + if (button9.isPressed()) { +// vol = 100/count + 25; + myInstrument.play(true); +// myInstrument.setVolume(vol); + VOL9 = constrain(map(analogRead(A9), TH9, 500, 30, 127), 30, 127); + //myInstrument.setMod(VOL9); + myInstrument.setVolume(VOL9); +// BJ == true; + Serial.print("Tone10 active at vol:"); + Serial.println(VOL9); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(41, HIGH); + } + else if(!CV) { + digitalWrite(41, LOW); + } + } + + if(button9.wasReleased()){ + myInstrument.pause (true); +// BJ == false; + + //Kill ControlVoltage + digitalWrite(41, LOW); + } +} diff --git a/sketches/max_sketch/Musicwithoutgluten6.2/Musicwithoutgluten6.2.ino b/sketches/max_sketch/Musicwithoutgluten6.2/Musicwithoutgluten6.2.ino new file mode 100644 index 0000000..888edd1 --- /dev/null +++ b/sketches/max_sketch/Musicwithoutgluten6.2/Musicwithoutgluten6.2.ino @@ -0,0 +1,571 @@ +#include + +#include +#include +#include + + +//note values +const char note1[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note5[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note6[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note7[] PROGMEM = ":d=128,b=300:f+"; //plays f5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:b+"; //plays b5 + +//instruments +MusicWithoutDelay myI(note1); +MusicWithoutDelay myIn(note2); +MusicWithoutDelay myIns(note3); +MusicWithoutDelay myInst(note4); +MusicWithoutDelay myInstr(note5); +MusicWithoutDelay myInstru(note6); +MusicWithoutDelay myInstrum(note7); +MusicWithoutDelay myInstrume(note8); +MusicWithoutDelay myInstrumen(note9); +MusicWithoutDelay myInstrument(note10); + + + + +int count; +//int vol; +//int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9; +bool CV; + +bool ZER; +bool ONE; +bool TWO; +bool THR; +bool FOU; +bool FIV; +bool SIX; +bool SEV; +bool EIG; +bool NIN; + +SensorToButton button0(TH0, pressUp, 50); +SensorToButton button1(TH1, pressUp, 50); +SensorToButton button2(TH2, pressUp, 50); +SensorToButton button3(TH3, pressUp, 50); +SensorToButton button4(TH4, pressUp, 50); +SensorToButton button5(TH5, pressUp, 50); +SensorToButton button6(TH6, pressUp, 50); +SensorToButton button7(TH7, pressUp, 50); +SensorToButton button8(TH8, pressUp, 50); +SensorToButton button9(TH9, pressUp, 50); + +void setup() { + Serial.begin(9600); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (analogRead(A0) + 20); + TH1 = (analogRead(A1) + 20); + TH2 = (analogRead(A2) + 20); + TH3 = (analogRead(A3) + 20); + TH4 = (analogRead(A4) + 20); + TH5 = (analogRead(A5) + 20); + TH6 = (analogRead(A6) + 20); + TH7 = (analogRead(A7) + 20); + TH8 = (analogRead(A8) + 20); + TH9 = (analogRead(A9) + 20); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + myI.begin(CHA, SINE, ENVELOPE0, 0); + myIn.begin(SINE, ENVELOPE0, 0); + myIns.begin(SINE, ENVELOPE0, 0); + myInst.begin(SINE, ENVELOPE0, 0); + myInstr.begin(SINE, ENVELOPE0, 0); + myInstru.begin(SINE, ENVELOPE0, 0); + myInstrum.begin(SINE, ENVELOPE0, 0); + myInstrume.begin(SINE, ENVELOPE0, 0); + myInstrumen.begin(SINE, ENVELOPE0, 0); + myInstrument.begin(SINE, ENVELOPE0, 0); + + myI.pause(true); + myIn.pause(true); + myIns.pause(true); + myInst.pause(true); + myInstr.pause(true); + myInstru.pause(true); + myInstrum.pause(true); + myInstrume.pause(true); + myInstrumen.pause(true); + myInstrument.pause(true); + + Serial.println("go!"); +} + +void loop() { + CV = digitalRead(22); + count = 0; + + button0.read (A0); + button1.read (A1); + button2.read (A2); + button3.read (A3); + button4.read (A4); + button5.read (A5); + button6.read (A6); + button7.read (A7); + button8.read (A8); + button9.read (A9); + + myI.update(); + myIn.update(); + myIns.update(); + myInst.update(); + myInstr.update(); + myInstru.update(); + myInstrum.update(); + myInstrume.update(); + myInstrumen.update(); + myInstrument.update(); + + + + //Messure LDR inputs + // VA0 = analogRead(A0); + // VA1 = analogRead(A1); + // VA2 = analogRead(A2); + // VA3 = analogRead(A3); + // + // Serial.print("VA0: "); Serial.println(VA0); + // Serial.print("VA1: "); Serial.println(VA1); + // Serial.print("VA2: "); Serial.println(VA2); + // Serial.print("VA3: "); Serial.println(VA3); + // Serial.println(" "); + + // VA4 = analogRead(A4); + // VA5 = analogRead(A5); + // VA6 = analogRead(A6); + // VA7 = analogRead(A7); + // + // Serial.print("VA4: "); Serial.println(VA4); + // Serial.print("VA5: "); Serial.println(VA5); + // Serial.print("VA6: "); Serial.println(VA6); + // Serial.print("VA7: "); Serial.println(VA7); + // Serial.println(" "); + + // VA8 = analogRead(A8); + // VA9 = analogRead(A9); + // + // Serial.print("VA8: "); Serial.println(VA8); + // Serial.print("VA9: "); Serial.println(VA9); + // Serial.println(" "); + + + if (button0.isPressed()) { + count++; + ZER == true; + } + else { + ZER == false; + } + + if (button1.isPressed()) { + count++; + ONE == true; + } + else { + ONE == false; + } + + if (button2.isPressed()) { + count++; + TWO == true; + } + else { + TWO == false; + } + + if (button3.isPressed()) { + count++; + THR == true; + } + else { + THR == false; + } + + } + if (button4.isPressed()) { + count++; + FOU == true; + } + else { + FOU == false; + } + + } + if (button5.isPressed()) { + count++; + FIV == true; + } + else { + FIV == false; + } + + } + if (button6.isPressed()) { + count++; + SIX == true; + } + else { + SIX == false; + } + + } + if (button7.isPressed()) { + count++; + SEV == true; + } + else { + SEV == false; + } + + } + if (button8.isPressed()) { + count++; + EIG == true; + } + else { + EIG == false; + } + + } + if (button9.isPressed()) { + count++; + NIN == true; + } + else { + NIN == false; + } + + } + + Serial.print("Intruments playing = "); + Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + //vol = 100/count + 25; + myI.play(true); + // myI.setVolume(vol); + VOL0 = constrain(map(analogRead(A0), TH0, 500, 30, 127), 30, 127); + //myI.setMod(VOL0); + myI.setVolume(VOL0); + // BA == true; + Serial.print("Tone0 active at vol:"); + Serial.println(VOL0); + Serial.println(analogRead(A0)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(23, HIGH); + } + else if (!CV) { + digitalWrite(23, LOW); + } + } + + if (!ZER) { + myI.pause (true); + // BA == false; + + //Kill ControlVoltage + digitalWrite(23, LOW); + } + + if (button1.isPressed()) { + // vol = 100/count + 25; + myIn.play(true); + // myIn.setVolume(vol); + VOL1 = constrain(map(analogRead(A1), TH1, 500, 30, 127), 30, 127); + //myIn.setMod(VOL1); + myIn.setVolume(VOL1); + // BB == true; + Serial.print("Tone1 active at vol:"); + Serial.println(VOL1); + Serial.println(analogRead(A1)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(25, HIGH); + } + else if (!CV) { + digitalWrite(25, LOW); + } + } + + if (button1.wasReleased()) { + myIn.pause (true); + // BB == false; + + //Kill ControlVoltage + digitalWrite(25, LOW); + } + + if (button2.isPressed()) { + // vol = 100/count + 25; + myIns.play(true); + // myIns.setVolume(vol); + VOL2 = constrain(map(analogRead(A2), TH2, 500, 30, 127), 30, 127); + //myIns.setMod(VOL2); + myIns.setVolume(VOL2); + // BC == true; + Serial.print("Tone2 active at vol:"); + Serial.println(VOL2); + Serial.println(analogRead(A2)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(27, HIGH); + } + else if (!CV) { + digitalWrite(27, LOW); + } + } + + if (button2.wasReleased()) { + myIns.pause (true); + // BC == false; + + //Kill ControlVoltage + digitalWrite(27, LOW); + } + + if (button3.isPressed()) { + // vol = 100/count + 25; + myInst.play(true); + // myInst.setVolume(vol); + VOL3 = constrain(map(analogRead(A3), TH3, 500, 30, 127), 30, 127); + //myInst.setMod(VOL3); + myInst.setVolume(VOL3); + // BD == true; + Serial.print("Tone3 active at vol:"); + Serial.println(VOL3); + Serial.println(analogRead(A3)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(29, HIGH); + } + else if (!CV) { + digitalWrite(29, LOW); + } + } + + if (button3.wasReleased()) { + myInst.pause (true); + // BD == false; + + //Kill ControlVoltage + digitalWrite(29, LOW); + } + + if (button4.isPressed()) { + // vol = 100/count + 25; + myInstr.play(true); + // myInstr.setVolume(vol); + VOL4 = constrain(map(analogRead(A4), TH4, 500, 30, 127), 30, 127); + //myInstr.setMod(VOL4); + myInstr.setVolume(VOL4); + // BE == true; + Serial.print("Tone4 active at vol:"); + Serial.println(VOL4); + Serial.println(analogRead(A4)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(31, HIGH); + } + else if (!CV) { + digitalWrite(31, LOW); + } + } + + if (button4.wasReleased()) { + myInstr.pause (true); + // BE == false; + + //Kill ControlVoltage + digitalWrite(31, LOW); + } + + if (button5.isPressed()) { + // vol = 100/count + 25; + myInstru.play(true); + // myInstru.setVolume(vol); + VOL5 = constrain(map(analogRead(A5), TH5, 500, 30, 127), 30, 127); + //myInstru.setMod(VOL5); + myInstru.setVolume(VOL5); + // BF == true; + Serial.print("Tone5 active at vol:"); + Serial.println(VOL5); + Serial.println(analogRead(A5)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(33, HIGH); + } + else if (!CV) { + digitalWrite(33, LOW); + } + } + + if (button5.wasReleased()) { + myInstru.pause (true); + // BF == false; + + //Kill ControlVoltage + digitalWrite(33, LOW); + } + + + if (button6.isPressed()) { + // vol = 100/count + 25; + myInstrum.play(true); + // myInstrum.setVolume(vol); + VOL6 = constrain(map(analogRead(A6), TH6, 500, 30, 127), 30, 127); + //myInstrum.setMod(VOL6); + myInstrum.setVolume(VOL6); + // BG == true; + Serial.print("Tone6 active at vol:"); + Serial.println(VOL6); + Serial.println(analogRead(A6)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(35, HIGH); + } + else if (!CV) { + digitalWrite(35, LOW); + } + } + + if (button6.wasReleased()) { + myInstrum.pause (true); + // BG == false; + + //Kill ControlVoltage + digitalWrite(35, LOW); + } + + if (button7.isPressed()) { + // vol = 100/count + 25; + myInstrume.play(true); + // myInstrume.setVolume(vol); + VOL7 = constrain(map(analogRead(A7), TH7, 500, 30, 127), 30, 127); + //myInstrume.setMod(VOL7); + myInstrume.setVolume(VOL7); + // BH == true; + Serial.print("Tone7 active at vol:"); + Serial.println(VOL7); + Serial.println(analogRead(A7)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(37, HIGH); + } + else if (!CV) { + digitalWrite(37, LOW); + } + } + + if (button7.wasReleased()) { + myInstrume.pause (true); + // BH == false; + + //Kill ControlVoltage + digitalWrite(37, LOW); + } + + + if (button8.isPressed()) { + // vol = 100/count + 25; + myInstrumen.play(true); + // myInstrumen.setVolume(vol); + VOL8 = constrain(map(analogRead(A8), TH8, 500, 30, 127), 30, 127); + //myInstrumen.setMod(VOL8); + myInstrumen.setVolume(VOL8); + // BI == true; + Serial.print("Tone8 active at vol:"); + Serial.println(VOL8); + Serial.println(analogRead(A8)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(39, HIGH); + } + else if (!CV) { + digitalWrite(39, LOW); + } + } + + if (button8.wasReleased()) { + myInstrumen.pause (true); + // BI == false; + + //Kill ControlVoltage + digitalWrite(39, LOW); + } + + if (button9.isPressed()) { + // vol = 100/count + 25; + myInstrument.play(true); + // myInstrument.setVolume(vol); + VOL9 = constrain(map(analogRead(A9), TH9, 500, 30, 127), 30, 127); + //myInstrument.setMod(VOL9); + myInstrument.setVolume(VOL9); + // BJ == true; + Serial.print("Tone00 active at vol:"); + Serial.println(VOL9); + Serial.println(analogRead(A9)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(41, HIGH); + } + else if (!CV) { + digitalWrite(41, LOW); + } + } + + if (button9.wasReleased()) { + myInstrument.pause (true); + // BJ == false; + + //Kill ControlVoltage + digitalWrite(41, LOW); + } +} diff --git a/sketches/max_sketch/Musicwithoutgluten6.3/Musicwithoutgluten6.3.ino b/sketches/max_sketch/Musicwithoutgluten6.3/Musicwithoutgluten6.3.ino new file mode 100644 index 0000000..11ef06a --- /dev/null +++ b/sketches/max_sketch/Musicwithoutgluten6.3/Musicwithoutgluten6.3.ino @@ -0,0 +1,564 @@ +#include + +#include +#include +#include + + +//note values +const char note1[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note5[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note6[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note7[] PROGMEM = ":d=128,b=300:f+"; //plays f5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:b+"; //plays b5 + +//instruments +MusicWithoutDelay myI(note1); +MusicWithoutDelay myIn(note2); +MusicWithoutDelay myIns(note3); +MusicWithoutDelay myInst(note4); +MusicWithoutDelay myInstr(note5); +MusicWithoutDelay myInstru(note6); +MusicWithoutDelay myInstrum(note7); +MusicWithoutDelay myInstrume(note8); +MusicWithoutDelay myInstrumen(note9); +MusicWithoutDelay myInstrument(note10); + + + + +int count; +//int vol; +//int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9; +bool CV; + +bool ZER; +bool ONE; +bool TWO; +bool THR; +bool FOU; +bool FIV; +bool SIX; +bool SEV; +bool EIG; +bool NIN; + +SensorToButton button0(TH0, pressUp, 50); +SensorToButton button1(TH1, pressUp, 50); +SensorToButton button2(TH2, pressUp, 50); +SensorToButton button3(TH3, pressUp, 50); +SensorToButton button4(TH4, pressUp, 50); +SensorToButton button5(TH5, pressUp, 50); +SensorToButton button6(TH6, pressUp, 50); +SensorToButton button7(TH7, pressUp, 50); +SensorToButton button8(TH8, pressUp, 50); +SensorToButton button9(TH9, pressUp, 50); + +void setup() { + Serial.begin(9600); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (analogRead(A0) + 20); + TH1 = (analogRead(A1) + 20); + TH2 = (analogRead(A2) + 20); + TH3 = (analogRead(A3) + 20); + TH4 = (analogRead(A4) + 20); + TH5 = (analogRead(A5) + 20); + TH6 = (analogRead(A6) + 20); + TH7 = (analogRead(A7) + 20); + TH8 = (analogRead(A8) + 20); + TH9 = (analogRead(A9) + 20); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + myI.begin(CHA, SINE, ENVELOPE0, 0); + myIn.begin(SINE, ENVELOPE0, 0); + myIns.begin(SINE, ENVELOPE0, 0); + myInst.begin(SINE, ENVELOPE0, 0); + myInstr.begin(SINE, ENVELOPE0, 0); + myInstru.begin(SINE, ENVELOPE0, 0); + myInstrum.begin(SINE, ENVELOPE0, 0); + myInstrume.begin(SINE, ENVELOPE0, 0); + myInstrumen.begin(SINE, ENVELOPE0, 0); + myInstrument.begin(SINE, ENVELOPE0, 0); + + myI.pause(true); + myIn.pause(true); + myIns.pause(true); + myInst.pause(true); + myInstr.pause(true); + myInstru.pause(true); + myInstrum.pause(true); + myInstrume.pause(true); + myInstrumen.pause(true); + myInstrument.pause(true); + + Serial.println("go!"); +} + +void loop() { + CV = digitalRead(22); + count = 0; + + button0.read (A0); + button1.read (A1); + button2.read (A2); + button3.read (A3); + button4.read (A4); + button5.read (A5); + button6.read (A6); + button7.read (A7); + button8.read (A8); + button9.read (A9); + + myI.update(); + myIn.update(); + myIns.update(); + myInst.update(); + myInstr.update(); + myInstru.update(); + myInstrum.update(); + myInstrume.update(); + myInstrumen.update(); + myInstrument.update(); + + + + //Messure LDR inputs + // VA0 = analogRead(A0); + // VA1 = analogRead(A1); + // VA2 = analogRead(A2); + // VA3 = analogRead(A3); + // + // Serial.print("VA0: "); Serial.println(VA0); + // Serial.print("VA1: "); Serial.println(VA1); + // Serial.print("VA2: "); Serial.println(VA2); + // Serial.print("VA3: "); Serial.println(VA3); + // Serial.println(" "); + + // VA4 = analogRead(A4); + // VA5 = analogRead(A5); + // VA6 = analogRead(A6); + // VA7 = analogRead(A7); + // + // Serial.print("VA4: "); Serial.println(VA4); + // Serial.print("VA5: "); Serial.println(VA5); + // Serial.print("VA6: "); Serial.println(VA6); + // Serial.print("VA7: "); Serial.println(VA7); + // Serial.println(" "); + + // VA8 = analogRead(A8); + // VA9 = analogRead(A9); + // + // Serial.print("VA8: "); Serial.println(VA8); + // Serial.print("VA9: "); Serial.println(VA9); + // Serial.println(" "); + + + if (button0.isPressed()) { + count++; + ZER == true; + } + else { + ZER == false; + } + + if (button1.isPressed()) { + count++; + ONE == true; + } + else { + ONE == false; + } + + if (button2.isPressed()) { + count++; + TWO == true; + } + else { + TWO == false; + } + + if (button3.isPressed()) { + count++; + THR == true; + } + else if{ + THR == false; + } + + if (button4.isPressed()) { + count++; + FOU == true; + } + else { + FOU == false; + } + + if (button5.isPressed()) { + count++; + FIV == true; + } + else { + FIV == false; + } + + if (button6.isPressed()) { + count++; + SIX == true; + } + else { + SIX == false; + } + + if (button7.isPressed()) { + count++; + SEV == true; + } + else { + SEV == false; + } + + if (button8.isPressed()) { + count++; + EIG == true; + } + else { + EIG == false; + } + + if (button9.isPressed()) { + count++; + NIN == true; + } + else { + NIN == false; + } + + + Serial.print("Intruments playing = "); + Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + //vol = 100/count + 25; + myI.play(true); + // myI.setVolume(vol); + VOL0 = constrain(map(analogRead(A0), TH0, 500, 30, 127), 30, 127); + //myI.setMod(VOL0); + myI.setVolume(VOL0); + // BA == true; + Serial.print("Tone0 active at vol:"); + Serial.println(VOL0); + Serial.println(analogRead(A0)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(23, HIGH); + } + else if (!CV) { + digitalWrite(23, LOW); + } + } + + if (!ZER) { + myI.pause (true); + // BA == false; + + //Kill ControlVoltage + digitalWrite(23, LOW); + } + + if (ONE) { + // vol = 100/count + 25; + myIn.play(true); + // myIn.setVolume(vol); + VOL1 = constrain(map(analogRead(A1), TH1, 500, 30, 127), 30, 127); + //myIn.setMod(VOL1); + myIn.setVolume(VOL1); + // BB == true; + Serial.print("Tone1 active at vol:"); + Serial.println(VOL1); + Serial.println(analogRead(A1)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(25, HIGH); + } + else if (!CV) { + digitalWrite(25, LOW); + } + } + + if (!ONE) { + myIn.pause (true); + // BB == false; + + //Kill ControlVoltage + digitalWrite(25, LOW); + } + + if (TWO) { + // vol = 100/count + 25; + myIns.play(true); + // myIns.setVolume(vol); + VOL2 = constrain(map(analogRead(A2), TH2, 500, 30, 127), 30, 127); + //myIns.setMod(VOL2); + myIns.setVolume(VOL2); + // BC == true; + Serial.print("Tone2 active at vol:"); + Serial.println(VOL2); + Serial.println(analogRead(A2)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(27, HIGH); + } + else if (!CV) { + digitalWrite(27, LOW); + } + } + + if (!TWO) { + myIns.pause (true); + // BC == false; + + //Kill ControlVoltage + digitalWrite(27, LOW); + } + + if (THR) { + // vol = 100/count + 25; + myInst.play(true); + // myInst.setVolume(vol); + VOL3 = constrain(map(analogRead(A3), TH3, 500, 30, 127), 30, 127); + //myInst.setMod(VOL3); + myInst.setVolume(VOL3); + // BD == true; + Serial.print("Tone3 active at vol:"); + Serial.println(VOL3); + Serial.println(analogRead(A3)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(29, HIGH); + } + else if (!CV) { + digitalWrite(29, LOW); + } + } + + if (!THR) { + myInst.pause (true); + // BD == false; + + //Kill ControlVoltage + digitalWrite(29, LOW); + } + + if (FOU) { + // vol = 100/count + 25; + myInstr.play(true); + // myInstr.setVolume(vol); + VOL4 = constrain(map(analogRead(A4), TH4, 500, 30, 127), 30, 127); + //myInstr.setMod(VOL4); + myInstr.setVolume(VOL4); + // BE == true; + Serial.print("Tone4 active at vol:"); + Serial.println(VOL4); + Serial.println(analogRead(A4)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(31, HIGH); + } + else if (!CV) { + digitalWrite(31, LOW); + } + } + + if (!FOU) { + myInstr.pause (true); + // BE == false; + + //Kill ControlVoltage + digitalWrite(31, LOW); + } + + if (FIV) { + // vol = 100/count + 25; + myInstru.play(true); + // myInstru.setVolume(vol); + VOL5 = constrain(map(analogRead(A5), TH5, 500, 30, 127), 30, 127); + //myInstru.setMod(VOL5); + myInstru.setVolume(VOL5); + // BF == true; + Serial.print("Tone5 active at vol:"); + Serial.println(VOL5); + Serial.println(analogRead(A5)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(33, HIGH); + } + else if (!CV) { + digitalWrite(33, LOW); + } + } + + if (!FIV) { + myInstru.pause (true); + // BF == false; + + //Kill ControlVoltage + digitalWrite(33, LOW); + } + + + if (SIX) { + // vol = 100/count + 25; + myInstrum.play(true); + // myInstrum.setVolume(vol); + VOL6 = constrain(map(analogRead(A6), TH6, 500, 30, 127), 30, 127); + //myInstrum.setMod(VOL6); + myInstrum.setVolume(VOL6); + // BG == true; + Serial.print("Tone6 active at vol:"); + Serial.println(VOL6); + Serial.println(analogRead(A6)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(35, HIGH); + } + else if (!CV) { + digitalWrite(35, LOW); + } + } + + if (!SIX) { + myInstrum.pause (true); + // BG == false; + + //Kill ControlVoltage + digitalWrite(35, LOW); + } + + if (SEV) { + // vol = 100/count + 25; + myInstrume.play(true); + // myInstrume.setVolume(vol); + VOL7 = constrain(map(analogRead(A7), TH7, 500, 30, 127), 30, 127); + //myInstrume.setMod(VOL7); + myInstrume.setVolume(VOL7); + // BH == true; + Serial.print("Tone7 active at vol:"); + Serial.println(VOL7); + Serial.println(analogRead(A7)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(37, HIGH); + } + else if (!CV) { + digitalWrite(37, LOW); + } + } + + if (!SEV) { + myInstrume.pause (true); + // BH == false; + + //Kill ControlVoltage + digitalWrite(37, LOW); + } + + + if (EIG) { + // vol = 100/count + 25; + myInstrumen.play(true); + // myInstrumen.setVolume(vol); + VOL8 = constrain(map(analogRead(A8), TH8, 500, 30, 127), 30, 127); + //myInstrumen.setMod(VOL8); + myInstrumen.setVolume(VOL8); + // BI == true; + Serial.print("Tone8 active at vol:"); + Serial.println(VOL8); + Serial.println(analogRead(A8)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(39, HIGH); + } + else if (!CV) { + digitalWrite(39, LOW); + } + } + + if (!EIG) { + myInstrumen.pause (true); + // BI == false; + + //Kill ControlVoltage + digitalWrite(39, LOW); + } + + if (NIN) { + // vol = 100/count + 25; + myInstrument.play(true); + // myInstrument.setVolume(vol); + VOL9 = constrain(map(analogRead(A9), TH9, 500, 30, 127), 30, 127); + //myInstrument.setMod(VOL9); + myInstrument.setVolume(VOL9); + // BJ == true; + Serial.print("Tone00 active at vol:"); + Serial.println(VOL9); + Serial.println(analogRead(A9)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(41, HIGH); + } + else if (!CV) { + digitalWrite(41, LOW); + } + } + + if (!NIN) { + myInstrument.pause (true); + // BJ == false; + + //Kill ControlVoltage + digitalWrite(41, LOW); + } +} diff --git a/sketches/max_sketch/Musicwithoutgluten6_noMulti/Musicwithoutgluten6_noMulti.ino b/sketches/max_sketch/Musicwithoutgluten6_noMulti/Musicwithoutgluten6_noMulti.ino new file mode 100644 index 0000000..71a81c8 --- /dev/null +++ b/sketches/max_sketch/Musicwithoutgluten6_noMulti/Musicwithoutgluten6_noMulti.ino @@ -0,0 +1,474 @@ +#include +#include +#include + +//note values +const char note1[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note5[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note6[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note7[] PROGMEM = ":d=128,b=300:f+"; //plays f5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:b+"; //plays b5 + +//instruments +MusicWithoutDelay myI(note1); +MusicWithoutDelay myIn(note2); +MusicWithoutDelay myIns(note3); +MusicWithoutDelay myInst(note4); +MusicWithoutDelay myInstr(note5); +MusicWithoutDelay myInstru(note6); +MusicWithoutDelay myInstrum(note7); +MusicWithoutDelay myInstrume(note8); +MusicWithoutDelay myInstrumen(note9); +MusicWithoutDelay myInstrument(note10); + +int count; +int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9; +bool CV; + +bool BA; +bool BB; +bool BC; +bool BD; +bool BE; +bool BF; +bool BG; +bool BH; +bool BI; +bool BJ; + +void setup() { + Serial.begin(9600); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (analogRead(A0)+20); + TH1 = (analogRead(A1)+20); + TH2 = (analogRead(A2)+20); + TH3 = (analogRead(A3)+20); + TH4 = (analogRead(A4)+20); + TH5 = (analogRead(A5)+20); + TH6 = (analogRead(A6)+20); + TH7 = (analogRead(A7)+20); + TH8 = (analogRead(A8)+20); + TH9 = (analogRead(A9)+20); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + + Serial.println("Wait4MWD"); + + Serial.println("Ini MWD"); + myI.begin(CHA, SINE, ENVELOPE0, 0); + myIn.begin(SINE, ENVELOPE0, 0); + myIns.begin(SINE, ENVELOPE0, 0); + myInst.begin(SINE, ENVELOPE0, 0); + myInstr.begin(SINE, ENVELOPE0, 0); + myInstru.begin(SINE, ENVELOPE0, 0); + myInstrum.begin(SINE, ENVELOPE0, 0); + myInstrume.begin(SINE, ENVELOPE0, 0); + myInstrumen.begin(SINE, ENVELOPE0, 0); + myInstrument.begin(SINE, ENVELOPE0, 0); + + myI.pause(true); + myIn.pause(true); + myIns.pause(true); + myInst.pause(true); + myInstr.pause(true); + myInstru.pause(true); + myInstrum.pause(true); + myInstrume.pause(true); + myInstrumen.pause(true); + myInstrument.pause(true); + + Serial.println("go!"); +} + +void loop() { + + myI.update(); + myIn.update(); + myIns.update(); + myInst.update(); + myInstr.update(); + myInstru.update(); + myInstrum.update(); + myInstrume.update(); + myInstrumen.update(); + myInstrument.update(); + + //Messure LDR multiplex inputs + VA0 = analogRead(A0); + VA1 = analogRead(A1); + VA2 = analogRead(A2); + VA3 = analogRead(A3); +// +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = analogRead(A4); + VA5 = analogRead(A5); + VA6 = analogRead(A6); + VA7 = analogRead(A7); +// +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = analogRead(A8); + VA9 = analogRead(A9); +// +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.println(" "); + + count = 0; + CV = digitalRead(22); + + if (VA0 > TH0) { + count++; + } + if (VA1 > TH1) { + count++; + } + if (VA2 > TH2) { + count++; + } + if (VA3 > TH3) { + count++; + } + if (VA4 > TH4) { + count++; + } + if (VA5 > TH5) { + count++; + } + if (VA6 > TH6) { + count++; + } + if (VA7 > TH7) { + count++; + } + if (VA8 > TH8) { + count++; + } + if (VA9 > TH9) { + count++; + } + +// Serial.print("Intruments playing = "); +// Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (VA0 > TH0 && !BA) { + vol = 100/count + 25; + myI.play(true); + myI.setVolume(vol); + VOL0 = constrain(map(VA0, TH0, 500, 30, 127), 30, 127); + //myI.setMod(VOL0); + myI.setVolume(VOL0); + BA == true; +// Serial.print("Tone1 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(23, HIGH); + } + else if (!CV) { + digitalWrite(23, LOW); + } + } + + else if (VA0 < TH0 && BA) { + myI.pause (true); + BA == false; + + //Kill ControlVoltage + digitalWrite(23, LOW); + } + + if (VA1 > TH1 && !BB) { + vol = 100/count + 25; + myIn.play(true); + myIn.setVolume(vol); + VOL1 = constrain(map(VA1, TH1, 500, 30, 127), 30, 127); + //myIn.setMod(VOL1); + myIn.setVolume(VOL1); + BB == true; +// Serial.print("Tone2 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(25, HIGH); + } + else if (!CV) { + digitalWrite(25, LOW); + } + } + + else if (VA1 < TH1 && BB) { + myIn.pause (true); + BB == false; + + //Kill ControlVoltage + digitalWrite(25, LOW); + } + + if (VA2 > TH2 && !BC) { + vol = 100/count + 25; + myIns.play(true); + myIns.setVolume(vol); + VOL2 = constrain(map(VA2, TH2, 500, 30, 127), 30, 127); + //myIns.setMod(VOL2); + myIns.setVolume(VOL2); + BC == true; +// Serial.print("Tone3 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(27, HIGH); + } + else if (!CV) { + digitalWrite(27, LOW); + } + } + + else if (VA2 < TH2 && BC) { + myIns.pause (true); + BC == false; + + //Kill ControlVoltage + digitalWrite(27, LOW); + } + + if (VA3 > TH3 && !BD) { + vol = 100/count + 25; + myInst.play(true); + myInst.setVolume(vol); + VOL3 = constrain(map(VA3, TH3, 500, 30, 127), 30, 127); + //myInst.setMod(VOL3); + myInst.setVolume(VOL3); + BD == true; +// Serial.print("Tone4 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(29, HIGH); + } + else if (!CV) { + digitalWrite(29, LOW); + } + } + + else if (VA3 < TH3 && BD) { + myInst.pause (true); + BD == false; + + //Kill ControlVoltage + digitalWrite(29, LOW); + } + + if (VA4 > TH4 && !BE) { + vol = 100/count + 25; + myInstr.play(true); + myInstr.setVolume(vol); + VOL4 = constrain(map(VA4, TH4, 500, 30, 127), 30, 127); + //myInstr.setMod(VOL4); + myInstr.setVolume(VOL4); + BE == true; +// Serial.print("Tone5 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(31, HIGH); + } + else if (!CV) { + digitalWrite(31, LOW); + } + } + + else if (VA4 < TH4 && BE) { + myInstr.pause (true); + BE == false; + + //Kill ControlVoltage + digitalWrite(31, LOW); + } + + if (VA5 > TH5 && !BF) { + vol = 100/count + 25; + myInstru.play(true); + myInstru.setVolume(vol); + VOL5 = constrain(map(VA5, TH5, 500, 30, 127), 30, 127); + //myInstru.setMod(VOL5); + myInstru.setVolume(VOL5); + BF == true; +// Serial.print("Tone6 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(33, HIGH); + } + else if (!CV) { + digitalWrite(33, LOW); + } + } + + else if (VA5 < TH5 && BF) { + myInstru.pause (true); + BF == false; + + //Kill ControlVoltage + digitalWrite(33, LOW); + } + + + if (VA6 > TH6 && !BG) { + vol = 100/count + 25; + myInstrum.play(true); + myInstrum.setVolume(vol); + VOL6 = constrain(map(VA6, TH6, 500, 30, 127),30, 127); + //myInstrum.setMod(VOL6); + myInstrum.setVolume(VOL6); + BG == true; +// Serial.print("Tone7 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(35, HIGH); + } + else if (!CV) { + digitalWrite(35, LOW); + } + } + + else if (VA6 < TH6 && BG) { + myInstrum.pause (true); + BG == false; + + //Kill ControlVoltage + digitalWrite(35, LOW); + } + + if (VA7 > TH7 && !BH) { + vol = 100/count + 25; + myInstrume.play(true); + myInstrume.setVolume(vol); + VOL7 = constrain(map(VA7, TH7, 500, 30, 127), 30, 127); + //myInstrume.setMod(VOL7); + myInstrume.setVolume(VOL7); + BH == true; +// Serial.print("Tone8 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(37, HIGH); + } + else if (!CV) { + digitalWrite(37, LOW); + } + } + + else if (VA7 < TH7 && BH) { + myInstrume.pause (true); + BH == false; + + //Kill ControlVoltage + digitalWrite(37, LOW); + } + + + if (VA8 > TH8 && !BI) { + vol = 100/count + 25; + myInstrumen.play(true); + myInstrumen.setVolume(vol); + VOL8 = constrain(map(VA8, TH8, 500, 30, 127), 30, 127); + //myInstrumen.setMod(VOL8); + myInstrumen.setVolume(VOL8); + BI == true; +// Serial.print("Tone9 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(39, HIGH); + } + else if (!CV) { + digitalWrite(39, LOW); + } + } + + else if (VA8 < TH8 && BI) { + myInstrumen.pause (true); + BI == false; + + //Kill ControlVoltage + digitalWrite(39, LOW); + } + + if (VA9 > TH9 && !BJ) { + vol = 100/count + 25; + myInstrument.play(true); + myInstrument.setVolume(vol); + VOL9 = constrain(map(VA9, TH9, 500, 30, 127), 30, 127); + //myInstrument.setMod(VOL9); + myInstrument.setVolume(VOL9); + BJ == true; +// Serial.print("Tone10 active at vol:"); +// Serial.println(vol); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(41, HIGH); + } + else if (!CV) { + digitalWrite(41, LOW); + } + } + + else if (VA9 < TH9 && BJ) { + myInstrument.pause (true); + BJ == false; + + //Kill ControlVoltage + digitalWrite(41, LOW); + } +} diff --git a/sketches/max_sketch/Musicwithoutgluten7/Musicwithoutgluten7.ino b/sketches/max_sketch/Musicwithoutgluten7/Musicwithoutgluten7.ino new file mode 100644 index 0000000..79dde24 --- /dev/null +++ b/sketches/max_sketch/Musicwithoutgluten7/Musicwithoutgluten7.ino @@ -0,0 +1,494 @@ +//#include + +#include +#include +#include + + +//note values +const char note0[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note1[] PROGMEM = ":d=128,b=300:d-1+"; //plays d4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:a-1+"; //plays a4 +const char note5[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note6[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note7[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 + +//instruments +MusicWithoutDelay myI(note0); +MusicWithoutDelay myIn(note1); +MusicWithoutDelay myIns(note2); +MusicWithoutDelay myInst(note3); +MusicWithoutDelay myInstr(note4); +MusicWithoutDelay myInstru(note5); +MusicWithoutDelay myInstrum(note6); +MusicWithoutDelay myInstrume(note7); +MusicWithoutDelay myInstrumen(note8); +MusicWithoutDelay myInstrument(note9); + + + + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9; +bool CV; + +bool ZER; +bool ONE; +bool TWO; +bool THR; +bool FOU; +bool FIV; +bool SIX; +bool SEV; +bool EIG; +bool NIN; + +void setup() { + Serial.begin(9600); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (analogRead(A0) + 40); + TH1 = (analogRead(A1) + 40); + TH2 = (analogRead(A2) + 40); + TH3 = (analogRead(A3) + 40); + TH4 = (analogRead(A4) + 40); + TH5 = (analogRead(A5) + 40); + TH6 = (analogRead(A6) + 40); + TH7 = (analogRead(A7) + 40); + TH8 = (analogRead(A8) + 40); + TH9 = (analogRead(A9) + 40); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + myI.begin(CHA, TRIANGLE, ENVELOPE0, 0); + myIn.begin(TRIANGLE, ENVELOPE0, 0); + myIns.begin(TRIANGLE, ENVELOPE0, 0); + myInst.begin(TRIANGLE, ENVELOPE0, 0); + myInstr.begin(TRIANGLE, ENVELOPE0, 0); + myInstru.begin(TRIANGLE, ENVELOPE0, 0); + myInstrum.begin(TRIANGLE, ENVELOPE0, 0); + myInstrume.begin(TRIANGLE, ENVELOPE0, 0); + myInstrumen.begin(TRIANGLE, ENVELOPE0, 0); + myInstrument.begin(TRIANGLE, ENVELOPE0, 0); + + myI.pause(true); + myIn.pause(true); + myIns.pause(true); + myInst.pause(true); + myInstr.pause(true); + myInstru.pause(true); + myInstrum.pause(true); + myInstrume.pause(true); + myInstrumen.pause(true); + myInstrument.pause(true); + + Serial.println("go!"); +} + +void loop() { + CV = digitalRead(22); + count = 0; + + myI.update(); + myIn.update(); + myIns.update(); + myInst.update(); + myInstr.update(); + myInstru.update(); + myInstrum.update(); + myInstrume.update(); + myInstrumen.update(); + myInstrument.update(); + + //Messure LDR inputs + VA0 = analogRead(A0); + VA1 = analogRead(A1); + VA2 = analogRead(A2); + VA3 = analogRead(A3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = analogRead(A4); + VA5 = analogRead(A5); + VA6 = analogRead(A6); + VA7 = analogRead(A7); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = analogRead(A8); + VA9 = analogRead(A9); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.println(" "); + + + if (VA0 > TH0) { + count++; + ZER = true; + } + else if (VA0 < TH0) { + ZER = false; + } + + if (VA1 > TH1) { + count++; + ONE = true; + } + else if (VA1 < TH1) { + ONE = false; + } + + if (VA2 > TH2) { + count++; + TWO = true; + } + else if (VA2 < TH2) { + TWO = false; + } + + if (VA3 > TH3) { + count++; + THR = true; + } + else if (VA3 < TH3) { + THR = false; + } + + if (VA4 > TH4) { + count++; + FOU = true; + } + else if (VA4 < TH4) { + FOU = false; + } + + if (VA5 > TH5) { + count++; + FIV = true; + } + else if (VA5 < TH5) { + FIV = false; + } + + if (VA6 > TH6) { + count++; + SIX = true; + } + else if (VA6 < TH6) { + SIX = false; + } + + if (VA7 > TH7) { + count++; + SEV = true; + } + else if (VA7 < TH7) { + SEV = false; + } + + if (VA8 > TH8) { + count++; + EIG = true; + } + else if (VA8 < TH8) { + EIG = false; + } + + if (VA9 > TH9) { + count++; + NIN = true; + } + else if (VA9 < TH9) { + NIN = false; + } + + +// Serial.print("Intruments playing = "); +// Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + myI.play(true); + VOL0 = 50/count+constrain(map(analogRead(A0), TH0, TH0+450, 0, 50), 0, 50); + myI.setVolume(VOL0); +// Serial.print("Tone0 active at vol:"); +// Serial.println(VOL0); +// Serial.println(analogRead(A0)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(23, HIGH); + } + else if (!CV) { + digitalWrite(23, LOW); + } + } + + if (!ZER) { + myI.pause (true); + + //Kill ControlVoltage + digitalWrite(23, LOW); + } + + if (ONE) { + myIn.play(true); + VOL1 = 50/count+constrain(map(analogRead(A1), TH1, TH1+450, 0, 50), 0, 50); + myIn.setVolume(VOL1); +// Serial.print("Tone1 active at vol:"); +// Serial.println(VOL1); +// Serial.println(analogRead(A1)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(25, HIGH); + } + else if (!CV) { + digitalWrite(25, LOW); + } + } + + if (!ONE) { + myIn.pause (true); + + //Kill ControlVoltage + digitalWrite(25, LOW); + } + + if (TWO) { + myIns.play(true); + VOL2 = 50/count+constrain(map(analogRead(A2), TH2, TH2+450, 0, 50), 0, 50); + myIns.setVolume(VOL2); +// Serial.print("Tone2 active at vol:"); +// Serial.println(VOL2); +// Serial.println(analogRead(A2)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(27, HIGH); + } + else if (!CV) { + digitalWrite(27, LOW); + } + } + + if (!TWO) { + myIns.pause (true); + + //Kill ControlVoltage + digitalWrite(27, LOW); + } + + if (THR) { + myInst.play(true); + VOL3 = 50/count+constrain(map(analogRead(A3), TH3, TH3+450, 0, 50), 0, 50); + myInst.setVolume(VOL3); + // BD == true; +// Serial.print("Tone3 active at vol:"); +// Serial.println(VOL3); +// Serial.println(analogRead(A3)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(29, HIGH); + } + else if (!CV) { + digitalWrite(29, LOW); + } + } + + if (!THR) { + myInst.pause (true); + + //Kill ControlVoltage + digitalWrite(29, LOW); + } + + if (FOU) { + myInstr.play(true); + VOL4 = 50/count+constrain(map(analogRead(A4), TH4, TH4+450, 0, 50), 0, 50); + myInstr.setVolume(VOL4); + // BE == true; +// Serial.print("Tone4 active at vol:"); +// Serial.println(VOL4); +// Serial.println(analogRead(A4)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(31, HIGH); + } + else if (!CV) { + digitalWrite(31, LOW); + } + } + + if (!FOU) { + myInstr.pause (true); + + //Kill ControlVoltage + digitalWrite(31, LOW); + } + + if (FIV) { + myInstru.play(true); + VOL5 = 50/count+constrain(map(analogRead(A5), TH5, TH5+450, 0, 50), 0, 50); + //myInstru.setMod(VOL5); + myInstru.setVolume(VOL5); +// Serial.print("Tone5 active at vol:"); +// Serial.println(VOL5); +// Serial.println(analogRead(A5)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(33, HIGH); + } + else if (!CV) { + digitalWrite(33, LOW); + } + } + + if (!FIV) { + myInstru.pause (true); + + //Kill ControlVoltage + digitalWrite(33, LOW); + } + + + if (SIX) { + myInstrum.play(true); + VOL6 = 50/count+constrain(map(analogRead(A6), TH6, TH6+450, 0, 50), 0, 50); + //myInstrum.setMod(VOL6); + myInstrum.setVolume(VOL6); +// Serial.print("Tone6 active at vol:"); +// Serial.println(VOL6); +// Serial.println(analogRead(A6)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(35, HIGH); + } + else if (!CV) { + digitalWrite(35, LOW); + } + } + + if (!SIX) { + myInstrum.pause (true); + + //Kill ControlVoltage + digitalWrite(35, LOW); + } + + if (SEV) { + myInstrume.play(true); + VOL7 = 50/count+constrain(map(analogRead(A7), TH7, TH7+450, 0, 50), 0, 50); + myInstrume.setVolume(VOL7); +// Serial.print("Tone7 active at vol:"); +// Serial.println(VOL7); +// Serial.println(analogRead(A7)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(37, HIGH); + } + else if (!CV) { + digitalWrite(37, LOW); + } + } + + if (!SEV) { + myInstrume.pause (true); + + //Kill ControlVoltage + digitalWrite(37, LOW); + } + + + if (EIG) { + myInstrumen.play(true); + VOL8 = 50/count+constrain(map(analogRead(A8), TH8, TH8+450, 0, 50), 0, 50); + myInstrumen.setVolume(VOL8); +// Serial.print("Tone8 active at vol:"); +// Serial.println(VOL8); +// Serial.println(analogRead(A8)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(39, HIGH); + } + else if (!CV) { + digitalWrite(39, LOW); + } + } + + if (!EIG) { + myInstrumen.pause (true); + + //Kill ControlVoltage + digitalWrite(39, LOW); + } + + if (NIN) { + myInstrument.play(true); + VOL9 = 50/count+constrain(map(analogRead(A9), TH9, TH9+450, 0, 50), 0, 50); + myInstrument.setVolume(VOL9); +// Serial.print("Tone9 active at vol:"); +// Serial.println(VOL9); +// Serial.println(analogRead(A9)); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(41, HIGH); + } + else if (!CV) { + digitalWrite(41, LOW); + } + } + + if (!NIN) { + myInstrument.pause (true); + + //Kill ControlVoltage + digitalWrite(41, LOW); + } +} diff --git a/sketches/max_sketch/Musicwithoutgluten_/Musicwithoutgluten_.ino b/sketches/max_sketch/Musicwithoutgluten_/Musicwithoutgluten_.ino new file mode 100644 index 0000000..9192bdd --- /dev/null +++ b/sketches/max_sketch/Musicwithoutgluten_/Musicwithoutgluten_.ino @@ -0,0 +1,341 @@ +#include +#include +#include +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + +//note values +const char note1[] PROGMEM = {"::c-1"}; //plays c4 +const char note2[] PROGMEM = {"::e-1"}; //plays e4 +const char note3[] PROGMEM = {"::f-1"}; //plays f4 +const char note4[] PROGMEM = {"::g-1"}; //plays g4 +const char note5[] PROGMEM = {"::c"}; //plays c5 +const char note6[] PROGMEM = {"::e"}; //plays e5 +const char note7[] PROGMEM = {"::f"}; //plays f5 +const char note8[] PROGMEM = {"::g"}; //plays g5 +//const char note9[] PROGMEM = {"::c+1"}; //plays c6 +//const char note10[] PROGMEM = {"::e+1"}; //plays e6 +//const char note11[] PROGMEM = {"::f+1"}; //plays f6 +//const char note12[] PROGMEM = {"::g+1"}; //plays g6 + + + + +//instruments +MusicWithoutDelay myI(note1); +MusicWithoutDelay myIn(note2); +MusicWithoutDelay myIns(note3); +MusicWithoutDelay myInst(note4); +MusicWithoutDelay myInstr(note5); +MusicWithoutDelay myInstru(note6); +MusicWithoutDelay myInstrum(note7); +MusicWithoutDelay myInstrume(note8); +//MusicWithoutDelay myInstrumen(note9); +//MusicWithoutDelay myInstrument(note10); +//MusicWithoutDelay myInstruments(note11); +//MusicWithoutDelay myInstrumentss(note12); + +int count; +int vol; +int TH; +int16_t adc0a, adc1a, adc2a, adc3a, adc0b, adc1b, adc2b, adc3b, adc0c, adc1c, adc2c, adc3c, adc0d, adc1d, adc2d, adc3d; +//bool codeswitch = false; + +bool BA; +bool BB; +bool BC; +bool BD; +bool BE; +bool BF; +bool BG; +bool BH; + + + +void setup() { + Serial.begin(115200); + + //set the gain for multiplexed ins + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + //start the multiplexing + Serial.println("Initializing Multiplexing "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("Multiplexing Initialized"); + + //calibrate the LDRs + Serial.println ("Calibrating"); + TH = (adsb.readADC_SingleEnded(3)); + Serial.print ("TH="); + Serial.println (TH); + + Serial.println("Initializing Music Without Delay"); + myI.begin(CHA, TRIANGLE, ENVELOPE0, 0); + myIn.begin(TRIANGLE, ENVELOPE0, 0); + myIns.begin(TRIANGLE, ENVELOPE0, 0); + myInst.begin(TRIANGLE, ENVELOPE0, 0); + Serial.println("Music Witout Delay Initialized"); + Serial.println("Start messuring LDRs"); +} + +void loop() { + +// myI.update(); +// myIn.update(); +// myIns.update(); +// myInst.update(); + + //Messure LDR multiplex inputs + + adc0a = adsa.readADC_SingleEnded(0); + adc1a = adsa.readADC_SingleEnded(1); + adc2a = adsa.readADC_SingleEnded(2); + adc3a = adsa.readADC_SingleEnded(3); + + Serial.print("AIN0A: "); Serial.println(adc0a); + Serial.print("AIN1A: "); Serial.println(adc1a); + Serial.print("AIN2A: "); Serial.println(adc2a); + Serial.print("AIN3A: "); Serial.println(adc3a); + Serial.println(" "); + + adc0b = adsb.readADC_SingleEnded(0); + adc1b = adsb.readADC_SingleEnded(1); + adc2b = adsb.readADC_SingleEnded(2); + adc3b = adsb.readADC_SingleEnded(3); + + Serial.print("AIN0B: "); Serial.println(adc0b); + Serial.print("AIN1B: "); Serial.println(adc1b); + Serial.print("AIN2B: "); Serial.println(adc2b); + Serial.print("AIN3B: "); Serial.println(adc3b); + Serial.println(" "); + + adc0c = adsc.readADC_SingleEnded(0); + adc1c = adsc.readADC_SingleEnded(1); + adc2c = adsc.readADC_SingleEnded(2); + adc3c = adsc.readADC_SingleEnded(3); + + Serial.print("AIN0C: "); Serial.println(adc0c); + Serial.print("AIN1C: "); Serial.println(adc1c); + Serial.print("AIN2C: "); Serial.println(adc2c); + Serial.print("AIN3C: "); Serial.println(adc3c); + Serial.println(" "); + + adc0d = adsd.readADC_SingleEnded(0); + adc1d = adsd.readADC_SingleEnded(1); + adc2d = adsd.readADC_SingleEnded(2); + adc3d = adsd.readADC_SingleEnded(3); + + Serial.print("AIN0D: "); Serial.println(adc0d); + Serial.print("AIN1D: "); Serial.println(adc1d); + Serial.print("AIN2D: "); Serial.println(adc2d); + Serial.print("AIN3D: "); Serial.println(adc3d); + Serial.println(" "); + + count = 0; + + if (adc0a < TH) { + count++; + } + if (adc1a < TH) { + count++; + } + if (adc2a < TH) { + count++; + } + if (adc3a < TH) { + count++; + } + if (adc0b < TH) { + count++; + } + if (adc1b < TH) { + count++; + } + if (adc2b < TH) { + count++; + } + if (adc3b < TH) { + count++; + } +// if (adc0c < TH) { +// count++; +// } +// if (adc1c < TH) { +// count++; +// } +// if (adc2c < TH) { +// count++; +// } +// if (adc3c < TH) { +// count++; +// } + + Serial.print("Intruments playing="); + Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (adc0a < TH && !BA) { + vol = 120/count; + myI.play(true); + myI.setVolume(vol); +// myI.setSustain(50); + //myI.setMod(int mod1 = map(adc0a, 3000, 60000, 0, 127); + BA == true; + Serial.print("Tone1 active at vol:"); + Serial.println(vol); + } + + else if (adc0a > TH && BA) { + myI.pause (true); + BA == false; + Serial.println("Tone1 not active"); + } + if (adc1a < TH && !BB) { + vol = 120/count; + myIn.play(true); + myIn.setVolume(vol); +// myIn.setSustain(50); + BB == true; + Serial.print("Tone2 active at vol:"); + Serial.println(vol); + } + + else if (adc1a > TH && BB) { + myIn.pause (true); + BB == false; + Serial.println("Tone2 not active"); + } + + if (adc2a < TH && !BC) { + vol = 120/count; + myIns.play(true); + myIns.setVolume(vol); +// myIns.setSustain(50); + BC == true; + Serial.print("Tone3 active at vol:"); + Serial.println(vol); + } + + else if (adc2a > TH && BC) { + myIns.pause (true); + BC == false; + Serial.println("Tone3 not active"); + } + + if (adc3a < TH && !BD) { + vol = 120/count; + myInst.play(true); + myInst.setVolume(vol); +// myInst.setSustain(50); + BD == true; + Serial.print("Tone4 active at vol:"); + Serial.println(vol); + } + + else if (adc3a < TH && BD) { + myInst.pause (true); + BD == false; + Serial.println("Tone4 not active"); + } + + if (adc0b < TH && !BE) { + vol = 120/count; + myInstr.play(true); + myInstr.setVolume(vol); +// myInst.setSustain(50); + BE == true; + Serial.print("Tone5 active at vol:"); + Serial.println(vol); + } + + else if (adc0b < TH && BE) { + myInstr.pause (true); + BE == false; + Serial.println("Tone5 not active"); + } + + if (adc1b < TH && !BF) { + vol = 120/count; + myInstru.play(true); + myInstru.setVolume(vol); +// myInst.setSustain(50); + BF == true; + Serial.print("Tone6 active at vol:"); + Serial.println(vol); + } + + else if (adc1b < TH && BF) { + myInstru.pause (true); + BF == false; + Serial.println("Tone6 not active"); + } + + + if (adc2b < TH && !BG) { + vol = 120/count; + myInstrum.play(true); + myInstrum.setVolume(vol); +// myInst.setSustain(50); + BG == true; + Serial.print("Tone7 active at vol:"); + Serial.println(vol); + } + + else if (adc2b < TH && BG) { + myInstrum.pause (true); + BG == false; + Serial.println("Tone7 not active"); + } + + if (adc3b < TH && !BH) { + vol = 120/count; + myInstrume.play(true); + myInstrume.setVolume(vol); +// myInst.setSustain(50); + BH == true; + Serial.print("Tone8 active at vol:"); + Serial.println(vol); + } + + else if (adc3b < TH && BH) { + myInstrume.pause (true); + BH == false; + Serial.println("Tone8 not active"); + } +// if (adc0b < TH) { +// //result += tone_5.next() * (1/count); +// } +// if (adc1b < TH) { +// //result += tone_6.next() * (1/count); +// } +// if (adc2b < TH) { +// //result += tone_7.next() * (1/count); +// } +// if (adc3b < TH) { +// //result += tone_8.next() * (1/count); +// } +// if (adc0c < TH) { +// //result += tone_9.next() * (1/count); +// } +// if (adc1c < TH) { +// //result += tone_10.next() * (1/count); +// } +// if (adc2c < TH) { +// //result += tone_11.next() * (1/count); +// } +// if (adc3c < TH) { +// //result += tone_12.next() * (1/count); +// } +} diff --git a/sketches/max_sketch/Musicwithoutgluten_4working/Musicwithoutgluten_4working.ino b/sketches/max_sketch/Musicwithoutgluten_4working/Musicwithoutgluten_4working.ino new file mode 100644 index 0000000..7d5c36c --- /dev/null +++ b/sketches/max_sketch/Musicwithoutgluten_4working/Musicwithoutgluten_4working.ino @@ -0,0 +1,331 @@ +#include +//#include +//#include + +// #include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +//Adafruit_ADS1115 adsc (0x4A); +//Adafruit_ADS1115 adsd (0x4B); + +//note values +const char note1[] PROGMEM = "::c"; //plays c +const char note2[] PROGMEM = "::e"; //plays e +const char note3[] PROGMEM = "::f"; //plays f +const char note4[] PROGMEM = "::g"; //plays g +//const char note5[] PROGMEM = {"::c"}; //plays c +//const char note6[] PROGMEM = {"::e"}; //plays e +//const char note7[] PROGMEM = {"::f"}; //plays f +//const char note8[] PROGMEM = {"::g"}; //plays g +//const char note9[] PROGMEM = {"::c+1"}; //plays c6 +//const char note10[] PROGMEM = {"::e+1"}; //plays e6 +//const char note11[] PROGMEM = {"::f+1"}; //plays f6 +//const char note12[] PROGMEM = {"::g+1"}; //plays g6 + + + + +//instruments +MusicWithoutDelay myI(note1); +MusicWithoutDelay myIn(note2); +MusicWithoutDelay myIns(note3); +MusicWithoutDelay myInst(note4); +//MusicWithoutDelay myInstr(note5); +//MusicWithoutDelay myInstru(note6); +//MusicWithoutDelay myInstrum(note7); +//MusicWithoutDelay myInstrume(note8); +//MusicWithoutDelay myInstrumen(note9); +//MusicWithoutDelay myInstrument(note10); +//MusicWithoutDelay myInstruments(note11); +//MusicWithoutDelay myInstrumentss(note12); + +int count; +int vol; +int TH; +int16_t adc0a, adc1a, adc2a, adc3a, adc0b, adc1b, adc2b, adc3b, adc0c, adc1c, adc2c, adc3c, adc0d, adc1d, adc2d, adc3d; +//bool codeswitch = false; + +bool BA; +bool BB; +bool BC; +bool BD; +//bool BE; +//bool BF; +//bool BG; +//bool BH; + + + +void setup() { + Serial.begin(9600); + + //set the gain for multiplexed ins + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); +// adsc.setGain(GAIN_ONE); +// adsd.setGain(GAIN_ONE); + + //start the multiplexing + Serial.println("Initializing Multiplexing "); + adsa.begin(); + adsb.begin(); +// adsc.begin(); +// adsd.begin(); + Serial.println("Multiplexing Initialized"); + + //calibrate the LDRs + Serial.println ("Calibrating"); + TH = (adsb.readADC_SingleEnded(3)/*-500*/); + Serial.print ("TH="); + Serial.println (TH); + + Serial.println("Waiting for Music Without Delay"); + + Serial.println("Initializing Music Without Delay"); + myI.begin(CHA, TRIANGLE, ENVELOPE0, 0); + myIn.begin(TRIANGLE, ENVELOPE0, 0); + myIns.begin(TRIANGLE, ENVELOPE0, 0); + myInst.begin(TRIANGLE, ENVELOPE0, 0); +// myInstr.begin(TRIANGLE, ENVELOPE0, 0); +// myInstru.begin(TRIANGLE, ENVELOPE0, 0); +// myInstrum.begin(TRIANGLE, ENVELOPE0, 0); +// myInstrume.begin(TRIANGLE, ENVELOPE0, 0); + Serial.println("Music Witout Delay Initialized"); + + Serial.println("Start messuring LDRs"); +} + +void loop() { + + myI.update(); + myIn.update(); + myIns.update(); + myInst.update(); +// myInstr.update(); +// myInstru.update(); +// myInstrum.update(); +// myInstrume.update(); + + //Messure LDR multiplex inputs + + adc0a = adsa.readADC_SingleEnded(0); + adc1a = adsa.readADC_SingleEnded(1); + adc2a = adsa.readADC_SingleEnded(2); + adc3a = adsa.readADC_SingleEnded(3); + + Serial.print("AIN0A: "); Serial.println(adc0a); + Serial.print("AIN1A: "); Serial.println(adc1a); + Serial.print("AIN2A: "); Serial.println(adc2a); + Serial.print("AIN3A: "); Serial.println(adc3a); + Serial.println(" "); + + adc0b = adsb.readADC_SingleEnded(0); + adc1b = adsb.readADC_SingleEnded(1); + adc2b = adsb.readADC_SingleEnded(2); + adc3b = adsb.readADC_SingleEnded(3); + + Serial.print("AIN0B: "); Serial.println(adc0b); + Serial.print("AIN1B: "); Serial.println(adc1b); + Serial.print("AIN2B: "); Serial.println(adc2b); + Serial.print("AIN3B: "); Serial.println(adc3b); + Serial.println(" "); + +// adc0c = adsc.readADC_SingleEnded(0); +// adc1c = adsc.readADC_SingleEnded(1); +// adc2c = adsc.readADC_SingleEnded(2); +// adc3c = adsc.readADC_SingleEnded(3); +// +// Serial.print("AIN0C: "); Serial.println(adc0c); +// Serial.print("AIN1C: "); Serial.println(adc1c); +// Serial.print("AIN2C: "); Serial.println(adc2c); +// Serial.print("AIN3C: "); Serial.println(adc3c); +// Serial.println(" "); +// +// adc0d = adsd.readADC_SingleEnded(0); +// adc1d = adsd.readADC_SingleEnded(1); +// adc2d = adsd.readADC_SingleEnded(2); +// adc3d = adsd.readADC_SingleEnded(3); +// +// Serial.print("AIN0D: "); Serial.println(adc0d); +// Serial.print("AIN1D: "); Serial.println(adc1d); +// Serial.print("AIN2D: "); Serial.println(adc2d); +// Serial.print("AIN3D: "); Serial.println(adc3d); +// Serial.println(" "); + + count = 0; + + if (adc0a > TH) { + count++; + } + if (adc1a > TH) { + count++; + } + if (adc2a > TH) { + count++; + } + if (adc3a > TH) { + count++; + } +// if (adc0b > TH) { +// count++; +// } +// if (adc1b > TH) { +// count++; +// } +// if (adc2b > TH) { +// count++; +// } +// if (adc3b > TH) { +// count++; +// } + + +// if (adc0c > TH) { +// count++; +// } +// if (adc1c > TH) { +// count++; +// } +// if (adc2c > TH) { +// count++; +// } +// if (adc3c >TH) { +// count++; +// } + + Serial.print("Intruments playing = "); + Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (adc0a > TH && !BA) { + vol = 125/count; + myI.play(true); + myI.setVolume(vol); + //myI.setSustain(100); + //myI.setMod(int mod1 = map(adc0a, 1000, 8000, 0, 127); + BA == true; + Serial.print("Tone1 active at vol:"); + Serial.println(vol); + } + + else if (adc0a < TH && BA) { + myI.pause (true); + BA == false; + Serial.println("Tone1 not active"); + } + if (adc1a > TH && !BB) { + vol = 125/count; + myIn.play(true); + myIn.setVolume(vol); + //myIn.setSustain(100); + BB == true; + Serial.print("Tone2 active at vol:"); + Serial.println(vol); + } + + else if (adc1a < TH && BB) { + myIn.pause (true); + BB == false; + Serial.println("Tone2 not active"); + } + + if (adc2a > TH && !BC) { + vol = 125/count; + myIns.play(true); + myIns.setVolume(vol); + //myIns.setSustain(100); + BC == true; + Serial.print("Tone3 active at vol:"); + Serial.println(vol); + } + + else if (adc2a < TH && BC) { + myIns.pause (true); + BC == false; + Serial.println("Tone3 not active"); + } + + if (adc3a > TH && !BD) { + vol = 125/count; + myInst.play(true); + myInst.setVolume(vol); + //myInst.setSustain(100); + BD == true; + Serial.print("Tone4 active at vol:"); + Serial.println(vol); + } + + else if (adc3a < TH && BD) { + myInst.pause (true); + BD == false; + Serial.println("Tone4 not active"); + } + +// if (adc0b > TH && !BE) { +// vol = 120/count; +// myInstr.play(true); +// myInstr.setVolume(vol); +//// myInst.setSustain(50); +// BE == true; +// Serial.print("Tone5 active at vol:"); +// Serial.println(vol); +// } +// +// else if (adc0b < TH && BE) { +// myInstr.pause (true); +// BE == false; +// Serial.println("Tone5 not active"); +// } +// +// if (adc1b > TH && !BF) { +// vol = 120/count; +// myInstru.play(true); +// myInstru.setVolume(vol); +//// myInst.setSustain(50); +// BF == true; +// Serial.print("Tone6 active at vol:"); +// Serial.println(vol); +// } +// +// else if (adc1b < TH && BF) { +// myInstru.pause (true); +// BF == false; +// Serial.println("Tone6 not active"); +// } +// +// +// if (adc2b > TH && !BG) { +// vol = 120/count; +// myInstrum.play(true); +// myInstrum.setVolume(vol); +//// myInst.setSustain(50); +// BG == true; +// Serial.print("Tone7 active at vol:"); +// Serial.println(vol); +// } +// +// else if (adc2b < TH && BG) { +// myInstrum.pause (true); +// BG == false; +// Serial.println("Tone7 not active"); +// } +// +// if (adc3b > TH && !BH) { +// vol = 120/count; +// myInstrume.play(true); +// myInstrume.setVolume(vol); +//// myInst.setSustain(50); +// BH == true; +// Serial.print("Tone8 active at vol:"); +// Serial.println(vol); +// } +// +// else if (adc3b < TH && BH) { +// myInstrume.pause (true); +// BH == false; +// Serial.println("Tone8 not active"); +// } +} diff --git a/sketches/max_sketch/Poly_Mplx_1/Adafruit_ADS1015.h b/sketches/max_sketch/Poly_Mplx_1/Adafruit_ADS1015.h new file mode 100644 index 0000000..5071dbc --- /dev/null +++ b/sketches/max_sketch/Poly_Mplx_1/Adafruit_ADS1015.h @@ -0,0 +1,150 @@ +/**************************************************************************/ +/*! + @file Adafruit_ADS1015.h + @author K. Townsend (Adafruit Industries) + @license BSD (see license.txt) + + This is a library for the Adafruit ADS1015 breakout board + ----> https://www.adafruit.com/products/??? + + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + @section HISTORY + + v1.0 - First release + v1.1 - Added ADS1115 support - W. Earl +*/ +/**************************************************************************/ + +#if ARDUINO >= 100 + #include "Arduino.h" +#else + #include "WProgram.h" +#endif + +#include + +/*========================================================================= + I2C ADDRESS/BITS + -----------------------------------------------------------------------*/ + #define ADS1015_ADDRESS (0x48) // 1001 000 (ADDR = GND) +/*=========================================================================*/ + +/*========================================================================= + CONVERSION DELAY (in mS) + -----------------------------------------------------------------------*/ + #define ADS1015_CONVERSIONDELAY (1) + #define ADS1115_CONVERSIONDELAY (8) +/*=========================================================================*/ + +/*========================================================================= + POINTER REGISTER + -----------------------------------------------------------------------*/ + #define ADS1015_REG_POINTER_MASK (0x03) + #define ADS1015_REG_POINTER_CONVERT (0x00) + #define ADS1015_REG_POINTER_CONFIG (0x01) + #define ADS1015_REG_POINTER_LOWTHRESH (0x02) + #define ADS1015_REG_POINTER_HITHRESH (0x03) +/*=========================================================================*/ + +/*========================================================================= + CONFIG REGISTER + -----------------------------------------------------------------------*/ + #define ADS1015_REG_CONFIG_OS_MASK (0x8000) + #define ADS1015_REG_CONFIG_OS_SINGLE (0x8000) // Write: Set to start a single-conversion + #define ADS1015_REG_CONFIG_OS_BUSY (0x0000) // Read: Bit = 0 when conversion is in progress + #define ADS1015_REG_CONFIG_OS_NOTBUSY (0x8000) // Read: Bit = 1 when device is not performing a conversion + + #define ADS1015_REG_CONFIG_MUX_MASK (0x7000) + #define ADS1015_REG_CONFIG_MUX_DIFF_0_1 (0x0000) // Differential P = AIN0, N = AIN1 (default) + #define ADS1015_REG_CONFIG_MUX_DIFF_0_3 (0x1000) // Differential P = AIN0, N = AIN3 + #define ADS1015_REG_CONFIG_MUX_DIFF_1_3 (0x2000) // Differential P = AIN1, N = AIN3 + #define ADS1015_REG_CONFIG_MUX_DIFF_2_3 (0x3000) // Differential P = AIN2, N = AIN3 + #define ADS1015_REG_CONFIG_MUX_SINGLE_0 (0x4000) // Single-ended AIN0 + #define ADS1015_REG_CONFIG_MUX_SINGLE_1 (0x5000) // Single-ended AIN1 + #define ADS1015_REG_CONFIG_MUX_SINGLE_2 (0x6000) // Single-ended AIN2 + #define ADS1015_REG_CONFIG_MUX_SINGLE_3 (0x7000) // Single-ended AIN3 + + #define ADS1015_REG_CONFIG_PGA_MASK (0x0E00) + #define ADS1015_REG_CONFIG_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3 + #define ADS1015_REG_CONFIG_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1 + #define ADS1015_REG_CONFIG_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2 (default) + #define ADS1015_REG_CONFIG_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4 + #define ADS1015_REG_CONFIG_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8 + #define ADS1015_REG_CONFIG_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16 + + #define ADS1015_REG_CONFIG_MODE_MASK (0x0100) + #define ADS1015_REG_CONFIG_MODE_CONTIN (0x0000) // Continuous conversion mode + #define ADS1015_REG_CONFIG_MODE_SINGLE (0x0100) // Power-down single-shot mode (default) + + #define ADS1015_REG_CONFIG_DR_MASK (0x00E0) + #define ADS1015_REG_CONFIG_DR_128SPS (0x0000) // 128 samples per second + #define ADS1015_REG_CONFIG_DR_250SPS (0x0020) // 250 samples per second + #define ADS1015_REG_CONFIG_DR_490SPS (0x0040) // 490 samples per second + #define ADS1015_REG_CONFIG_DR_920SPS (0x0060) // 920 samples per second + #define ADS1015_REG_CONFIG_DR_1600SPS (0x0080) // 1600 samples per second (default) + #define ADS1015_REG_CONFIG_DR_2400SPS (0x00A0) // 2400 samples per second + #define ADS1015_REG_CONFIG_DR_3300SPS (0x00C0) // 3300 samples per second + + #define ADS1015_REG_CONFIG_CMODE_MASK (0x0010) + #define ADS1015_REG_CONFIG_CMODE_TRAD (0x0000) // Traditional comparator with hysteresis (default) + #define ADS1015_REG_CONFIG_CMODE_WINDOW (0x0010) // Window comparator + + #define ADS1015_REG_CONFIG_CPOL_MASK (0x0008) + #define ADS1015_REG_CONFIG_CPOL_ACTVLOW (0x0000) // ALERT/RDY pin is low when active (default) + #define ADS1015_REG_CONFIG_CPOL_ACTVHI (0x0008) // ALERT/RDY pin is high when active + + #define ADS1015_REG_CONFIG_CLAT_MASK (0x0004) // Determines if ALERT/RDY pin latches once asserted + #define ADS1015_REG_CONFIG_CLAT_NONLAT (0x0000) // Non-latching comparator (default) + #define ADS1015_REG_CONFIG_CLAT_LATCH (0x0004) // Latching comparator + + #define ADS1015_REG_CONFIG_CQUE_MASK (0x0003) + #define ADS1015_REG_CONFIG_CQUE_1CONV (0x0000) // Assert ALERT/RDY after one conversions + #define ADS1015_REG_CONFIG_CQUE_2CONV (0x0001) // Assert ALERT/RDY after two conversions + #define ADS1015_REG_CONFIG_CQUE_4CONV (0x0002) // Assert ALERT/RDY after four conversions + #define ADS1015_REG_CONFIG_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default) +/*=========================================================================*/ + +typedef enum +{ + GAIN_TWOTHIRDS = ADS1015_REG_CONFIG_PGA_6_144V, + GAIN_ONE = ADS1015_REG_CONFIG_PGA_4_096V, + GAIN_TWO = ADS1015_REG_CONFIG_PGA_2_048V, + GAIN_FOUR = ADS1015_REG_CONFIG_PGA_1_024V, + GAIN_EIGHT = ADS1015_REG_CONFIG_PGA_0_512V, + GAIN_SIXTEEN = ADS1015_REG_CONFIG_PGA_0_256V +} adsGain_t; + +class Adafruit_ADS1015 +{ +protected: + // Instance-specific properties + uint8_t m_i2cAddress; + uint8_t m_conversionDelay; + uint8_t m_bitShift; + adsGain_t m_gain; + + public: + Adafruit_ADS1015(uint8_t i2cAddress = ADS1015_ADDRESS); + void begin(void); + uint16_t readADC_SingleEnded(uint8_t channel); + int16_t readADC_Differential_0_1(void); + int16_t readADC_Differential_2_3(void); + void startComparator_SingleEnded(uint8_t channel, int16_t threshold); + int16_t getLastConversionResults(); + void setGain(adsGain_t gain); + adsGain_t getGain(void); + + private: +}; + +// Derive from ADS1105 & override construction to set properties +class Adafruit_ADS1115 : public Adafruit_ADS1015 +{ + public: + Adafruit_ADS1115(uint8_t i2cAddress = ADS1015_ADDRESS); + + private: +}; diff --git a/sketches/max_sketch/Poly_Mplx_1/Poly_Mplx_1.ino b/sketches/max_sketch/Poly_Mplx_1/Poly_Mplx_1.ino new file mode 100644 index 0000000..b348f74 --- /dev/null +++ b/sketches/max_sketch/Poly_Mplx_1/Poly_Mplx_1.ino @@ -0,0 +1,152 @@ +#include +#include + +#include +#include +#include +//#include /*Only required for reverb*/ +//#include +//ReverbTank reverb; + +//Multiplex adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + +#define CONTROL_RATE 64 // powers of 2 please + +Oscil tone_1(SQUARE_NO_ALIAS_2048_DATA); +Oscil tone_2(SQUARE_NO_ALIAS_2048_DATA); +Oscil tone_3(SQUARE_NO_ALIAS_2048_DATA); + +int count= 0; +boolean note1 = false; +boolean note2 = false; +boolean note3 = false; +boolean codeswitch = false; + + +void setup(){ + + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + //start the multiplexing + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + + startMozzi(CONTROL_RATE); + tone_1.setFreq(262); + tone_1.setPhase(120); + tone_2.setFreq(330); + tone_2.setPhase(240 ); + tone_3.setFreq(392); +} +void updateControl(){ + //Log number of notes playing + if (note1){ + count++; + } + if (note2){ + count++; + } + if (note3){ + count++; + } +} + + +int updateAudio(){ + int result = 0; + + //Play notes and mix down (according to notes playing + if (note1) { + result += tone_1.next() * (1/count); + } + if (note2) { + result += tone_2.next() * (1/count); + } + if (note3) { + result += tone_3.next() * (1/count); + } + //int arev = reverb.next(result); /*Initialize reverb*/ + + //return result + (arev>>3); /*Reverb: Mix signal*/ + //return arev; /*Reverb: Wet signal*/ + //return result; /*Reverb: Dry signal*/ + + //if (!codeswitch){ + //polysynth + return result; + //} + //else if (codeswitch) { + //controlvoltage + //return CV; + //} + + +} + +void loop(){ + //Messure LDR multiplex inputs + int16_t adc0a, adc1a, adc2a, adc3a, adc0b, adc1b, adc2b, adc3b, adc0c, adc1c, adc2c, adc3c, adc0d, adc1d, adc2d, adc3d; + + adc0a = adsa.readADC_SingleEnded(0); + adc1a = adsa.readADC_SingleEnded(1); + adc2a = adsa.readADC_SingleEnded(2); + adc3a = adsa.readADC_SingleEnded(3); +// Serial.print("AIN0A: "); Serial.println(adc0a); +// Serial.print("AIN1A: "); Serial.println(adc1a); +// Serial.print("AIN2A: "); Serial.println(adc2a); +// Serial.print("AIN3A: "); Serial.println(adc3a); +// Serial.println(" "); + + adc0b = adsb.readADC_SingleEnded(0); + adc1b = adsb.readADC_SingleEnded(1); + adc2b = adsb.readADC_SingleEnded(2); + adc3b = adsb.readADC_SingleEnded(3); +// Serial.print("AIN0B: "); Serial.println(adc0b); +// Serial.print("AIN1B: "); Serial.println(adc1b); +// Serial.print("AIN2B: "); Serial.println(adc2b); +// Serial.print("AIN3B: "); Serial.println(adc3b); +// Serial.println(" "); + + adc0c = adsc.readADC_SingleEnded(0); + adc1c = adsc.readADC_SingleEnded(1); + adc2c = adsc.readADC_SingleEnded(2); + adc3c = adsc.readADC_SingleEnded(3); +// Serial.print("AIN0C: "); Serial.println(adc0c); +// Serial.print("AIN1C: "); Serial.println(adc1c); +// Serial.print("AIN2C: "); Serial.println(adc2c); +// Serial.print("AIN3C: "); Serial.println(adc3c); +// Serial.println(" "); + + adc0d = adsd.readADC_SingleEnded(0); + adc1d = adsd.readADC_SingleEnded(1); + adc2d = adsd.readADC_SingleEnded(2); + adc3d = adsd.readADC_SingleEnded(3); +// Serial.print("AIN0D: "); Serial.println(adc0d); +// Serial.print("AIN1D: "); Serial.println(adc1d); +// Serial.print("AIN2D: "); Serial.println(adc2d); +// Serial.print("AIN3D: "); Serial.println(adc3d); +// Serial.println(" "); + +// delay(1000); + audioHook(); + + +//Switch between auditive output and CV out +// if (digitalRead (8) == LOW){ +// codeswitch = false; +// } +// if (digitalRead (8) == HIGH){ +// codeswitch = true; +// } + + +} diff --git a/sketches/max_sketch/Poly_Mplx_2_noMozzi/Poly_Mplx_2_noMozzi.ino b/sketches/max_sketch/Poly_Mplx_2_noMozzi/Poly_Mplx_2_noMozzi.ino new file mode 100644 index 0000000..f90fb9b --- /dev/null +++ b/sketches/max_sketch/Poly_Mplx_2_noMozzi/Poly_Mplx_2_noMozzi.ino @@ -0,0 +1,110 @@ +#include +#include +#include +#include +#include +SensorToButton btn(2, 50); //pin, debounce time(ms) +synthEngine mixer(20E3); +#define NUM 8 +MusicWithoutDelay instruments[NUM]; +int vol = 0; +uint16_t INTERVAL = 15; +bool mode = true; +int flip = 1; +// int pins[6] = {CHA,CHB,6,9,22,23}; //for Teensy 3+ +int pins[2] = {CHA,CHB}; + + +//multiplex adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + +int count= 0; +int TH; +int16_t adc0a, adc1a, adc2a, adc3a, adc0b, adc1b, adc2b, adc3b, adc0c, adc1c, adc2c, adc3c, adc0d, adc1d, adc2d, adc3d; +boolean codeswitch = false; + + +void setup(){ + //set the gain for multiplexed ins + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + //start the multiplexing + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + +for (byte i = 0; i < NUM; i++) { + MusicWithoutDelay *myInstrument = &instruments[i]; + float freq = MusicWithoutDelay::getNoteAsFrequency(NOTE_A3 + i * 4); //Function gives Frequceny using a Formula. Every other 4 notes is a harmonic major(something like that) + myInstrument->begin(pins[i%2], SINE, ENVELOPE0, 0).setVolume(0).setFrequency(freq); //set up instruments and their frequencies + + } + + //set tone frequency and phase +// tone_1.setFreq(165); +// tone_1.setPhase(0); +// tone_2.setFreq(196); +// tone_2.setPhase(30); +// tone_3.setFreq(220); +// tone_3.setPhase(60); +// tone_4.setFreq(262); +// tone_4.setPhase(90); +// tone_5.setFreq(330); +// tone_5.setPhase(120); +// tone_6.setFreq(392); +// tone_6.setPhase(150); +// tone_7.setFreq(440); +// tone_7.setPhase(180); +// tone_8.setFreq(523); +// tone_8.setPhase(210); +// tone_9.setFreq(659); +// tone_9.setPhase(240); +// tone_10.setFreq(784); +// tone_10.setPhase(270); +// tone_11.setFreq(880); +// tone_11.setPhase(300); +// tone_12.setFreq(1047); +// tone_12.setPhase(330); + + //calibrate (set treshold) + TH = adsb.readADC_SingleEnded(3); +} + + + +uint32_t pMillis, serialMillis; +void loop(){ +uint32_t cMillis = millis(); + btn.read(); + // if (cMillis - serialMillis > 500) { + for (byte i = 0; i < NUM; i++) { + MusicWithoutDelay *myInstrument = &instruments[i]; + myInstrument->update().setVolume(vol); //update instruments + } + // serialMillis = cMillis; + // } + if (mode) { + vol = analogRead(potPin); + vol = map(vol, 0, 1023, 0, 127); + } + else { + if (cMillis - pMillis >= INTERVAL) { //Vibrato + vol += flip; + if (vol < 90 || vol > 126) { + flip *= -1; + } + pMillis = cMillis; + } + } + if (btn.wasPressed()) { + vol = 95; + mode = !mode; + } +} diff --git a/sketches/max_sketch/Poly_Mplx_2_smplfd/Poly_Mplx_2_smplfd.ino b/sketches/max_sketch/Poly_Mplx_2_smplfd/Poly_Mplx_2_smplfd.ino new file mode 100644 index 0000000..43a9acf --- /dev/null +++ b/sketches/max_sketch/Poly_Mplx_2_smplfd/Poly_Mplx_2_smplfd.ino @@ -0,0 +1,194 @@ +#include +#include + + + +#include +#include +#include +//#include +//#include + +#define CONTROL_RATE 128 // powers of 2 please + +Oscil tone_1(SAW256_DATA); +Oscil tone_2(SAW256_DATA); +Oscil tone_3(SAW256_DATA); +Oscil tone_4(SAW256_DATA); +Oscil tone_5(SAW256_DATA); +Oscil tone_6(SAW256_DATA); +Oscil tone_7(SAW256_DATA); +Oscil tone_8(SAW256_DATA); +Oscil tone_9(SAW256_DATA); +Oscil tone_10(SAW256_DATA); +Oscil tone_11(SAW256_DATA); +Oscil tone_12(SAW256_DATA); + +//multiplex adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + +int count= 0; +int TH; +int16_t adc0a, adc1a, adc2a, adc3a, adc0b, adc1b, adc2b, adc3b, adc0c, adc1c, adc2c, adc3c, adc0d, adc1d, adc2d, adc3d; +boolean note1 = false; +boolean note2 = false; +boolean note3 = false; +boolean codeswitch = false; + + +void setup(){ + //set the gain for multiplexed ins + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + //start the multiplexing + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + + startMozzi(CONTROL_RATE); + + //set tone frequency and phase + tone_1.setFreq(165); + tone_1.setPhase(0); + tone_2.setFreq(196); + tone_2.setPhase(30); + tone_3.setFreq(220); + tone_3.setPhase(60); + tone_4.setFreq(262); + tone_4.setPhase(90); + tone_5.setFreq(330); + tone_5.setPhase(120); + tone_6.setFreq(392); + tone_6.setPhase(150); + tone_7.setFreq(440); + tone_7.setPhase(180); + tone_8.setFreq(523); + tone_8.setPhase(210); + tone_9.setFreq(659); + tone_9.setPhase(240); + tone_10.setFreq(784); + tone_10.setPhase(270); + tone_11.setFreq(880); + tone_11.setPhase(300); + tone_12.setFreq(1047); + tone_12.setPhase(330); + + //calibrate (set treshold) + TH = adsb.readADC_SingleEnded(3); +} + +void updateControl(){ + //log number of notes playing + if (adc0a < TH) { + count++; + } + if (adc1a < TH) { + count++; + } + if (adc2a < TH) { + count++; + } + if (adc3a < TH) { + count++; + } + if (adc0b < TH) { + count++; + } + if (adc1b < TH) { + count++; + } + if (adc2b < TH) { + count++; + } + if (adc3b < TH) { + count++; + } + if (adc0c < TH) { + count++; + } + if (adc1c < TH) { + count++; + } + if (adc2c < TH) { + count++; + } + if (adc3c < TH) { + count++; + } +} + + +int updateAudio(){ + int result = 0; + + //Play notes and mix down (according to notes playing + if (adc0a < TH) { + result += tone_1.next() * (1/count); + } + if (adc1a < TH) { + result += tone_2.next() * (1/count); + } + if (adc2a < TH) { + result += tone_3.next() * (1/count); + } + if (adc3a < TH) { + result += tone_4.next() * (1/count); + } + if (adc0b < TH) { + result += tone_5.next() * (1/count); + } + if (adc1b < TH) { + result += tone_6.next() * (1/count); + } + if (adc2b < TH) { + result += tone_7.next() * (1/count); + } + if (adc3b < TH) { + result += tone_8.next() * (1/count); + } + if (adc0c < TH) { + result += tone_9.next() * (1/count); + } + if (adc1c < TH) { + result += tone_10.next() * (1/count); + } + if (adc2c < TH) { + result += tone_11.next() * (1/count); + } + if (adc3c < TH) { + result += tone_12.next() * (1/count); + } + return result; +} + +void loop(){ + //Messure LDR multiplex inputs + adc0a = adsa.readADC_SingleEnded(0); + adc1a = adsa.readADC_SingleEnded(1); + adc2a = adsa.readADC_SingleEnded(2); + adc3a = adsa.readADC_SingleEnded(3); + + adc0b = adsb.readADC_SingleEnded(0); + adc1b = adsb.readADC_SingleEnded(1); + adc2b = adsb.readADC_SingleEnded(2); + adc3b = adsb.readADC_SingleEnded(3); + + adc0c = adsc.readADC_SingleEnded(0); + adc1c = adsc.readADC_SingleEnded(1); + adc2c = adsc.readADC_SingleEnded(2); + adc3c = adsc.readADC_SingleEnded(3); + + adc0d = adsd.readADC_SingleEnded(0); + adc1d = adsd.readADC_SingleEnded(1); + adc2d = adsd.readADC_SingleEnded(2); + adc3d = adsd.readADC_SingleEnded(3); + + audioHook(); +} diff --git a/sketches/max_sketch/mozzi_zonder_pit_2/mozzi_zonder_pit_2.ino b/sketches/max_sketch/mozzi_zonder_pit_2/mozzi_zonder_pit_2.ino new file mode 100644 index 0000000..9189269 --- /dev/null +++ b/sketches/max_sketch/mozzi_zonder_pit_2/mozzi_zonder_pit_2.ino @@ -0,0 +1,713 @@ +#include +#include +#include +#include // for envelope +#include +#include + +#include +#include + +//#include +//#include +//#include + +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + + +//note values +//const char note0[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +//const char note1[] PROGMEM = ":d=128,b=300:d-1+"; //plays d4 +//const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +//const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +//const char note4[] PROGMEM = ":d=128,b=300:a-1+"; //plays a4 +//const char note5[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +//const char note6[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +//const char note7[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +//const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +//const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +//const char note10[] PROGMEM = ":d=128,b=300:c+1+"; //plays c6 +//const char note11[] PROGMEM = ":d=128,b=300:d+1+"; //plays d6 +//const char note12[] PROGMEM = ":d=128,b=300:e+1+"; //plays e6 +//const char note13[] PROGMEM = ":d=128,b=300:g+1+"; //plays g6 +//const char note14[] PROGMEM = ":d=128,b=300:a+1+"; //plays a6 +//const char note15[] PROGMEM = ":d=128,b=300:c+2+"; //plays c7 + +//instruments +//MusicWithoutDelay Insta(note0); +//MusicWithoutDelay Instb(note1); +//MusicWithoutDelay Instc(note2); +//MusicWithoutDelay Instd(note3); +//MusicWithoutDelay Inste(note4); +//MusicWithoutDelay Instf(note5); +//MusicWithoutDelay Instg(note6); +//MusicWithoutDelay Insth(note7); +//MusicWithoutDelay Insti(note8); +//MusicWithoutDelay Instj(note9); +//MusicWithoutDelay Instk(note10); +//MusicWithoutDelay Instl(note11); +//MusicWithoutDelay Instm(note12); +//MusicWithoutDelay Instn(note13); +//MusicWithoutDelay Insto(note14); +//MusicWithoutDelay Instp(note15); + +#define CONTROL_RATE 64 +#define ATTACK 50 // long enough for control rate to catch it +#define DECAY 50 +#define SUSTAIN 600000 // Sustain 60 seconds unless a noteOff comes. +#define RELEASE 1000 +#define ATTACK_LEVEL 255 +#define DECAY_LEVEL 255 + +Oscil <2048, AUDIO_RATE> Insta(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instb(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instc(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instd(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Inste(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instf(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instg(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Insth(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Insti(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instj(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instk(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instl(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instm(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instn(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Insto(SIN2048_DATA); +Oscil <2048, AUDIO_RATE> Instp(SIN2048_DATA); + +ADSR envelope1; + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9, VA10, VA11, VA12, VA13, VA14, VA15; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9, TH10, TH11, TH12, TH13, TH14, TH15; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9, VOL10, VOL11, VOL12, VOL13, VOL14, VOL15; +bool CV; + +bool ZER; +bool ONE; +bool TWO; +bool THR; +bool FOU; +bool FIV; +bool SIX; +bool SEV; +bool EIG; +bool NIN; +bool TEN; +bool ELE; +bool TWE; +bool THT; +bool FOT; +bool FIT; + +void setup() { + Serial.begin(9600); + + //set the gain for multiplexed INs + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + Serial.println("Ini MPX "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("MPX Ini"); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (adsa.readADC_SingleEnded(0) + 800); + TH1 = (adsa.readADC_SingleEnded(1) + 800); + TH2 = (adsa.readADC_SingleEnded(2) + 800); + TH3 = (adsa.readADC_SingleEnded(3) + 800); + TH4 = (adsb.readADC_SingleEnded(0) + 800); + TH5 = (adsb.readADC_SingleEnded(1) + 800); + TH6 = (adsb.readADC_SingleEnded(2) + 800); + TH7 = (adsb.readADC_SingleEnded(3) + 800); + TH8 = (adsc.readADC_SingleEnded(0) + 800); + TH9 = (adsc.readADC_SingleEnded(1) + 800); + TH10 = (adsc.readADC_SingleEnded(2) + 800); + TH11 = (adsc.readADC_SingleEnded(3) + 800); + TH12 = (adsd.readADC_SingleEnded(0) + 800); + TH13 = (adsd.readADC_SingleEnded(1) + 800); + TH14 = (adsd.readADC_SingleEnded(2) + 800); + TH15 = (adsd.readADC_SingleEnded(3) + 800); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + Serial.print ("TH10="); + Serial.println (TH10); + Serial.print ("TH11="); + Serial.println (TH11); + Serial.print ("TH12="); + Serial.println (TH12); + Serial.print ("TH13="); + Serial.println (TH13); + Serial.print ("TH14="); + Serial.println (TH14); + Serial.print ("TH15="); + Serial.println (TH15); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + + Insta.setFreq(165); + Insta.setPhase(0); + Instb.setFreq(196); + Instb.setPhase(30); + Instc.setFreq(220); + Instc.setPhase(60); + Instd.setFreq(262); + Instd.setPhase(90); + Inste.setFreq(330); + Inste.setPhase(120); + Instf.setFreq(392); + Instf.setPhase(150); + Instg.setFreq(440); + Instg.setPhase(180); + Insth.setFreq(523); + Insth.setPhase(210); + Insti.setFreq(659); + Insti.setPhase(240); + Instj.setFreq(784); + Instj.setPhase(270); + Instk.setFreq(880); + Instk.setPhase(300); + Instl.setFreq(1047); + Instl.setPhase(330); + Instm.setFreq(659); + Instm.setPhase(240); + Instn.setFreq(784); + Instn.setPhase(270); + Insto.setFreq(880); + Insto.setPhase(300); + Instp.setFreq(1047); + Instp.setPhase(330); + + envelope1.setADLevels(ATTACK_LEVEL,DECAY_LEVEL); + envelope1.setTimes(ATTACK,DECAY,SUSTAIN,RELEASE); +// +// Insta.begin(CHA, TRIANGLE, ENVELOPE2, 0); +// Instb.begin(TRIANGLE, ENVELOPE2, 0); +// Instc.begin(TRIANGLE, ENVELOPE2, 0); +// Instd.begin(TRIANGLE, ENVELOPE2, 0); +// Inste.begin(TRIANGLE, ENVELOPE2, 0); +// Instf.begin(TRIANGLE, ENVELOPE2, 0); +// Instg.begin(TRIANGLE, ENVELOPE2, 0); +// Insth.begin(TRIANGLE, ENVELOPE2, 0); +// Insti.begin(TRIANGLE, ENVELOPE2, 0); +// Instj.begin(TRIANGLE, ENVELOPE2, 0); +// Instk.begin(TRIANGLE, ENVELOPE2, 0); +// Instl.begin(TRIANGLE, ENVELOPE2, 0); +// Instm.begin(TRIANGLE, ENVELOPE2, 0); +// Instn.begin(TRIANGLE, ENVELOPE2, 0); +// Insto.begin(TRIANGLE, ENVELOPE2, 0); +// Instp.begin(TRIANGLE, ENVELOPE2, 0); +// +// Insta.pause(true); +// Instb.pause(true); +// Instc.pause(true); +// Instd.pause(true); +// Inste.pause(true); +// Instf.pause(true); +// Instg.pause(true); +// Insth.pause(true); +// Insti.pause(true); +// Instj.pause(true); +// Instk.pause(true); +// Instl.pause(true); +// Instm.pause(true); +// Instn.pause(true); +// Insto.pause(true); +// Instp.pause(true); + + startMozzi(CONTROL_RATE); + + Serial.println("go!"); +} + +void updateControl(){ + if (VA0 > TH0) { + count++; + ZER = true; + if (CV) { + digitalWrite(0, HIGH); + } + else if (!CV) { + digitalWrite(0, LOW); + } + } + else if (VA0 < TH0) { + ZER = false; + //Kill ControlVoltage + digitalWrite(0, LOW); + } + + if (VA1 > TH1) { + count++; + ONE = true; + if (CV) { + digitalWrite(1, HIGH); + } + else if (!CV) { + digitalWrite(1, LOW); + } + } + else if (VA1 < TH1) { + ONE = false; + //Kill ControlVoltage + digitalWrite(1, LOW); + } + + if (VA2 > TH2) { + count++; + TWO = true; + if (CV) { + digitalWrite(2, HIGH); + } + else if (!CV) { + digitalWrite(2, LOW); + } + } + else if (VA2 < TH2) { + TWO = false; + //Kill ControlVoltage + digitalWrite(2, LOW); + } + + if (VA3 > TH3) { + count++; + THR = true; + if (CV) { + digitalWrite(3, HIGH); + } + else if (!CV) { + digitalWrite(3, LOW); + } + } + else if (VA3 < TH3) { + THR = false; + //Kill ControlVoltage + digitalWrite(3, LOW); + } + + if (VA4 > TH4) { + count++; + FOU = true; + if (CV) { + digitalWrite(4, HIGH); + } + else if (!CV) { + digitalWrite(4, LOW); + } + } + else if (VA4 < TH4) { + FOU = false; + //Kill ControlVoltage + digitalWrite(4, LOW); + } + + if (VA5 > TH5) { + if (CV) { + digitalWrite(5, HIGH); + } + else if (!CV) { + digitalWrite(5, LOW); + } + count++; + FIV = true; + } + else if (VA5 < TH5) { + FIV = false; + //Kill ControlVoltage + digitalWrite(5, LOW); + } + + if (VA6 > TH6) { + count++; + SIX = true; + if (CV) { + digitalWrite(6, HIGH); + } + else if (!CV) { + digitalWrite(6, LOW); + } + } + else if (VA6 < TH6) { + SIX = false; + //Kill ControlVoltage + digitalWrite(6, LOW); + } + + if (VA7 > TH7) { + count++; + SEV = true; + if (CV) { + digitalWrite(7, HIGH); + } + else if (!CV) { + digitalWrite(7, LOW); + } + } + else if (VA7 < TH7) { + SEV = false; + //Kill ControlVoltage + digitalWrite(7, LOW); + } + + if (VA8 > TH8) { + count++; + EIG = true; + if (CV) { + digitalWrite(8, HIGH); + } + else if (!CV) { + digitalWrite(8, LOW); + } + } + else if (VA8 < TH8) { + EIG = false; + //Kill ControlVoltage + digitalWrite(8, LOW); + + } + + if (VA9 > TH9) { + count++; + NIN = true; + if (CV) { + digitalWrite(9, HIGH); + } + else if (!CV) { + digitalWrite(9, LOW); + } + } + else if (VA9 < TH9) { + NIN = false; + //Kill ControlVoltage + digitalWrite(9, LOW); + } + + if (VA10 > TH10) { + count++; + TEN = true; + if (CV) { + digitalWrite(10, HIGH); + } + else if (!CV) { + digitalWrite(10, LOW); + } + } + else if (VA10 < TH10) { + TEN = false; + //Kill ControlVoltage + digitalWrite(10, LOW); + } + + if (VA11 > TH11) { + count++; + ELE = true; + if (CV) { + digitalWrite(11, HIGH); + } + else if (!CV) { + digitalWrite(11, LOW); + } + } + else if (VA11 < TH11) { + ELE = false; + //Kill ControlVoltage + digitalWrite(11, LOW); + } + + if (VA12 > TH12) { + count++; + TWE = true; + if (CV) { + digitalWrite(12, HIGH); + } + else if (!CV) { + digitalWrite(12, LOW); + } + } + else if (VA12 < TH12) { + TWE = false; + //Kill ControlVoltage + digitalWrite(12, LOW); + } + + if (VA13 > TH13) { + count++; + THT = true; + if (CV) { + digitalWrite(13, HIGH); + } + else if (!CV) { + digitalWrite(13, LOW); + } + } + else if (VA13 < TH13) { + THT = false; + //Kill ControlVoltage + digitalWrite(13, LOW); + } + + if (VA14 > TH14) { + count++; + FOT = true; + if (CV) { + digitalWrite(14, HIGH); + } + else if (!CV) { + digitalWrite(14, LOW); + } + } + else if (VA14 < TH14) { + FOT = false; + //Kill ControlVoltage + digitalWrite(14, LOW); + } + + if (VA15 > TH15) { + count++; + FIT = true; + if (CV) { + digitalWrite(15, HIGH); + } + else if (!CV) { + digitalWrite(15, LOW); + } + } + else if (VA15 < TH15) { + FIT = false; + //Kill ControlVoltage + digitalWrite(15, LOW); + } + + +// Serial.print("Intruments playing = "); +// Serial.println(count); +} + +int updateAudio(){ + int result = 0; + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + //envelope1.update(); + //return Insta.noteOn()); + return (Insta) (envelope1.noteOn()); + } + + if (!ZER) { + envelope1.noteOff(); + } + + if (ONE) { +// VOL1 = 50/count+constrain(map(VA1, TH1, TH1+5000, 0, 65), 0, 65); + result += Instb.next(); + } + + if (!ONE) { + } + + if (TWO) { + result += Instc.next(); + } + + if (!TWO) { + } + + if (THR) { + result += Instd.next(); + } + + if (!THR) { + } + + if (FOU) { + result += Inste.next(); + } + + if (!FOU) { + } + + if (FIV) { + result += Instf.next(); + } + + if (!FIV) { + } + + if (SIX) { + result += Instg.next(); + } + + if (!SIX) { + } + + if (SEV) { + result += Insth.next(); + } + + if (!SEV) { + } + + + if (EIG) { + result += Insti.next(); + } + + if (!EIG) { + } + + if (NIN) { + result += Instj.next(); + } + + if (!NIN) { + } + + if (TEN) { + result += Instk.next(); + } + + if (!TEN) { + } + + if (ELE) { + result += Instl.next(); + } + + if (!ELE) { + } + + if (TWE) { + result += Instm.next(); + } + + if (!TWE) { + } + + if (THT) { + result += Instn.next(); + } + + if (!THT) { + } + + if (FOT) { + result += Insto.next(); + } + + if (!FOT) { + } + + + if (FIT) { + result += Instp.next(); + } + + if (!FIT) { + } + return; +} + +void loop() { + CV = digitalRead(22); + count = 0; + +// Insta.update(); +// Instb.update(); +// Instc.update(); +// Instd.update(); +// Inste.update(); +// Instf.update(); +// Instg.update(); +// Insth.update(); +// Insti.update(); +// Instj.update(); +// Instk.update(); +// Instl.update(); +// Instm.update(); +// Instn.update(); +// Insto.update(); +// Instp.update(); + + //Messure LDR inputs + VA0 = adsa.readADC_SingleEnded(0); + VA1 = adsa.readADC_SingleEnded(1); + VA2 = adsa.readADC_SingleEnded(2); + VA3 = adsa.readADC_SingleEnded(3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = adsb.readADC_SingleEnded(0); + VA5 = adsb.readADC_SingleEnded(1); + VA6 = adsb.readADC_SingleEnded(2); + VA7 = adsb.readADC_SingleEnded(3); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = adsc.readADC_SingleEnded(0); + VA9 = adsc.readADC_SingleEnded(1); + VA10 = adsc.readADC_SingleEnded(2); + VA11 = adsc.readADC_SingleEnded(3); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.print("VA10: "); Serial.println(VA10); +// Serial.print("VA11: "); Serial.println(VA11); +// Serial.println(" "); + + VA12 = adsd.readADC_SingleEnded(0); + VA13 = adsd.readADC_SingleEnded(1); + VA14 = adsd.readADC_SingleEnded(2); + VA15 = adsd.readADC_SingleEnded(3); + +// Serial.print("VA12: "); Serial.println(VA12); +// Serial.print("VA13: "); Serial.println(VA13); +// Serial.print("VA14: "); Serial.println(VA14); +// Serial.print("VA15: "); Serial.println(VA15); +// Serial.println(" "); + + +audioHook(); +} diff --git a/sketches/max_sketch/muziek_zonder_pit/muziek_zonder_pit.ino b/sketches/max_sketch/muziek_zonder_pit/muziek_zonder_pit.ino new file mode 100644 index 0000000..b3f488e --- /dev/null +++ b/sketches/max_sketch/muziek_zonder_pit/muziek_zonder_pit.ino @@ -0,0 +1,773 @@ +#include +#include +#include + +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + + +//note values +const char note0[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note1[] PROGMEM = ":d=128,b=300:d-1+"; //plays d4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:a-1+"; //plays a4 +const char note5[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note6[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note7[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:c+1+"; //plays c6 +const char note11[] PROGMEM = ":d=128,b=300:d+1+"; //plays d6 +const char note12[] PROGMEM = ":d=128,b=300:e+1+"; //plays e6 +const char note13[] PROGMEM = ":d=128,b=300:g+1+"; //plays g6 +const char note14[] PROGMEM = ":d=128,b=300:a+1+"; //plays a6 +const char note15[] PROGMEM = ":d=128,b=300:c+2+"; //plays c7 + +//instruments +MusicWithoutDelay Insta(note0); +MusicWithoutDelay Instb(note1); +MusicWithoutDelay Instc(note2); +MusicWithoutDelay Instd(note3); +MusicWithoutDelay Inste(note4); +MusicWithoutDelay Instf(note5); +MusicWithoutDelay Instg(note6); +MusicWithoutDelay Insth(note7); +MusicWithoutDelay Insti(note8); +MusicWithoutDelay Instj(note9); +MusicWithoutDelay Instk(note10); +MusicWithoutDelay Instl(note11); +MusicWithoutDelay Instm(note12); +MusicWithoutDelay Instn(note13); +MusicWithoutDelay Insto(note14); +MusicWithoutDelay Instp(note15); + + + + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9, VA10, VA11, VA12, VA13, VA14, VA15; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9, TH10, TH11, TH12, TH13, TH14, TH15; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9, VOL10, VOL11, VOL12, VOL13, VOL14, VOL15; +bool CV; + +bool ZER; +bool ONE; +bool TWO; +bool THR; +bool FOU; +bool FIV; +bool SIX; +bool SEV; +bool EIG; +bool NIN; +bool TEN; +bool ELE; +bool TWE; +bool THT; +bool FOT; +bool FIT; + +void setup() { + Serial.begin(115200); + + //set the gain for multiplexed INs + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + Serial.println("Ini MPX "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("MPX Ini"); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (adsa.readADC_SingleEnded(0) + 800); + TH1 = (adsa.readADC_SingleEnded(1) + 800); + TH2 = (adsa.readADC_SingleEnded(2) + 800); + TH3 = (adsa.readADC_SingleEnded(3) + 800); + TH4 = (adsb.readADC_SingleEnded(0) + 800); + TH5 = (adsb.readADC_SingleEnded(1) + 800); + TH6 = (adsb.readADC_SingleEnded(2) + 800); + TH7 = (adsb.readADC_SingleEnded(3) + 800); + TH8 = (adsc.readADC_SingleEnded(0) + 800); + TH9 = (adsc.readADC_SingleEnded(1) + 800); + TH10 = (adsc.readADC_SingleEnded(2) + 800); + TH11 = (adsc.readADC_SingleEnded(3) + 800); + TH12 = (adsd.readADC_SingleEnded(0) + 800); + TH13 = (adsd.readADC_SingleEnded(1) + 800); + TH14 = (adsd.readADC_SingleEnded(2) + 800); + TH15 = (adsd.readADC_SingleEnded(3) + 800); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + Serial.print ("TH10="); + Serial.println (TH10); + Serial.print ("TH11="); + Serial.println (TH11); + Serial.print ("TH12="); + Serial.println (TH12); + Serial.print ("TH13="); + Serial.println (TH13); + Serial.print ("TH14="); + Serial.println (TH14); + Serial.print ("TH15="); + Serial.println (TH15); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + Insta.begin(CHA, TRIANGLE, ENVELOPE0, 0); + Instb.begin(TRIANGLE, ENVELOPE0, 0); + Instc.begin(TRIANGLE, ENVELOPE0, 0); + Instd.begin(TRIANGLE, ENVELOPE0, 0); + Inste.begin(TRIANGLE, ENVELOPE0, 0); + Instf.begin(TRIANGLE, ENVELOPE0, 0); + Instg.begin(TRIANGLE, ENVELOPE0, 0); + Insth.begin(TRIANGLE, ENVELOPE0, 0); + Insti.begin(TRIANGLE, ENVELOPE0, 0); + Instj.begin(TRIANGLE, ENVELOPE0, 0); + Instk.begin(TRIANGLE, ENVELOPE0, 0); + Instl.begin(TRIANGLE, ENVELOPE0, 0); + Instm.begin(TRIANGLE, ENVELOPE0, 0); + Instn.begin(TRIANGLE, ENVELOPE0, 0); + Insto.begin(TRIANGLE, ENVELOPE0, 0); + Instp.begin(TRIANGLE, ENVELOPE0, 0); + + Insta.pause(true); + Instb.pause(true); + Instc.pause(true); + Instd.pause(true); + Inste.pause(true); + Instf.pause(true); + Instg.pause(true); + Insth.pause(true); + Insti.pause(true); + Instj.pause(true); + Instk.pause(true); + Instl.pause(true); + Instm.pause(true); + Instn.pause(true); + Insto.pause(true); + Instp.pause(true); + + Serial.println("go!"); +} + +void loop() { + CV = digitalRead(22); + count = 0; + + Insta.update(); + Instb.update(); + Instc.update(); + Instd.update(); + Inste.update(); + Instf.update(); + Instg.update(); + Insth.update(); + Insti.update(); + Instj.update(); + Instk.update(); + Instl.update(); + Instm.update(); + Instn.update(); + Insto.update(); + Instp.update(); + + //Messure LDR inputs + VA0 = adsa.readADC_SingleEnded(0); + VA1 = adsa.readADC_SingleEnded(1); + VA2 = adsa.readADC_SingleEnded(2); + VA3 = adsa.readADC_SingleEnded(3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = adsb.readADC_SingleEnded(0); + VA5 = adsb.readADC_SingleEnded(1); + VA6 = adsb.readADC_SingleEnded(2); + VA7 = adsb.readADC_SingleEnded(3); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = adsc.readADC_SingleEnded(0); + VA9 = adsc.readADC_SingleEnded(1); + VA10 = adsc.readADC_SingleEnded(2); + VA11 = adsc.readADC_SingleEnded(3); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.print("VA10: "); Serial.println(VA10); +// Serial.print("VA11: "); Serial.println(VA11); +// Serial.println(" "); + + VA12 = adsd.readADC_SingleEnded(0); + VA13 = adsd.readADC_SingleEnded(1); + VA14 = adsd.readADC_SingleEnded(2); + VA15 = adsd.readADC_SingleEnded(3); + +// Serial.print("VA12: "); Serial.println(VA12); +// Serial.print("VA13: "); Serial.println(VA13); +// Serial.print("VA14: "); Serial.println(VA14); +// Serial.print("VA15: "); Serial.println(VA15); +// Serial.println(" "); + + + + if (VA0 > TH0) { + count++; + ZER = true; + } + else if (VA0 < TH0) { + ZER = false; + } + + if (VA1 > TH1) { + count++; + ONE = true; + } + else if (VA1 < TH1) { + ONE = false; + } + + if (VA2 > TH2) { + count++; + TWO = true; + } + else if (VA2 < TH2) { + TWO = false; + } + + if (VA3 > TH3) { + count++; + THR = true; + } + else if (VA3 < TH3) { + THR = false; + } + + if (VA4 > TH4) { + count++; + FOU = true; + } + else if (VA4 < TH4) { + FOU = false; + } + + if (VA5 > TH5) { + count++; + FIV = true; + } + else if (VA5 < TH5) { + FIV = false; + } + + if (VA6 > TH6) { + count++; + SIX = true; + } + else if (VA6 < TH6) { + SIX = false; + } + + if (VA7 > TH7) { + count++; + SEV = true; + } + else if (VA7 < TH7) { + SEV = false; + } + + if (VA8 > TH8) { + count++; + EIG = true; + } + else if (VA8 < TH8) { + EIG = false; + } + + if (VA9 > TH9) { + count++; + NIN = true; + } + else if (VA9 < TH9) { + NIN = false; + } + + if (VA10 > TH10) { + count++; + TEN = true; + } + else if (VA10 < TH10) { + TEN = false; + } + + if (VA11 > TH11) { + count++; + ELE = true; + } + else if (VA11 < TH11) { + ELE = false; + } + + if (VA12 > TH12) { + count++; + TWE = true; + } + else if (VA12 < TH12) { + TWE = false; + } + + if (VA13 > TH13) { + count++; + THT = true; + } + else if (VA13 < TH13) { + THT = false; + } + + if (VA14 > TH14) { + count++; + FOT = true; + } + else if (VA14 < TH14) { + FOT = false; + } + + if (VA15 > TH15) { + count++; + FIT = true; + } + else if (VA15 < TH15) { + FIT = false; + } + + +// Serial.print("Intruments playing = "); +// Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + VOL0 = 50/count+constrain(map(VA0, TH0, TH0+5000, 0, 65), 0, 65); + Insta.play(true); + Insta.setVolume(VOL0); +// Serial.print("Tone0 active at vol:"); +// Serial.println(VOL0); +// Serial.println(VA0); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(0, HIGH); + } + else if (!CV) { + digitalWrite(0, LOW); + } + } + + if (!ZER) { + Insta.pause (true); + + //Kill ControlVoltage + digitalWrite(0, LOW); + } + + if (ONE) { + VOL1 = 50/count+constrain(map(VA1, TH1, TH1+5000, 0, 65), 0, 65); + Instb.play(true); + Instb.setVolume(VOL1); +// Serial.print("Tone1 active at vol:"); +// Serial.println(VOL1); +// Serial.println(VA1); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(1, HIGH); + } + else if (!CV) { + digitalWrite(1, LOW); + } + } + + if (!ONE) { + Instb.pause (true); + + //Kill ControlVoltage + digitalWrite(1, LOW); + } + + if (TWO) { + VOL2 = 50/count+constrain(map(VA2, TH2, TH2+5000, 0, 65), 0, 65); + Instc.play(true); + Instc.setVolume(VOL2); +// Serial.print("Tone2 active at vol:"); +// Serial.println(VOL2); +// Serial.println(VA2); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(2, HIGH); + } + else if (!CV) { + digitalWrite(2, LOW); + } + } + + if (!TWO) { + Instc.pause (true); + + //Kill ControlVoltage + digitalWrite(2, LOW); + } + + if (THR) { + VOL3 = 50/count+constrain(map(VA3, TH3, TH3+5000, 0, 65), 0, 65); + Instd.play(true); + Instd.setVolume(VOL3); +// Serial.print("Tone3 active at vol:"); +// Serial.println(VOL3); +// Serial.println(VA3); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(3, HIGH); + } + else if (!CV) { + digitalWrite(3, LOW); + } + } + + if (!THR) { + Instd.pause (true); + + //Kill ControlVoltage + digitalWrite(3, LOW); + } + + if (FOU) { + VOL4 = 50/count+constrain(map(VA4, TH4, TH4+5000, 0, 65), 0, 65); + Inste.play(true); + Inste.setVolume(VOL4); +// Serial.print("Tone4 active at vol:"); +// Serial.println(VOL4); +// Serial.println(VA4); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(4, HIGH); + } + else if (!CV) { + digitalWrite(4, LOW); + } + } + + if (!FOU) { + Inste.pause (true); + + //Kill ControlVoltage + digitalWrite(4, LOW); + } + + if (FIV) { + VOL5 = 50/count+constrain(map(VA5, TH5, TH5+5000, 0, 65), 0, 65); + Instf.play(true); + Instf.setVolume(VOL5); +// Serial.print("Tone5 active at vol:"); +// Serial.println(VOL5); +// Serial.println(VA5); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(5, HIGH); + } + else if (!CV) { + digitalWrite(5, LOW); + } + } + + if (!FIV) { + Instf.pause (true); + + //Kill ControlVoltage + digitalWrite(5, LOW); + } + + + if (SIX) { + VOL6 = 50/count+constrain(map(VA6, TH6, TH6+5000, 0, 65), 0, 65); + Instg.play(true); + Instg.setVolume(VOL6); +// Serial.print("Tone6 active at vol:"); +// Serial.println(VOL6); +// Serial.println(VA6); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(6, HIGH); + } + else if (!CV) { + digitalWrite(6, LOW); + } + } + + if (!SIX) { + Instg.pause (true); + + //Kill ControlVoltage + digitalWrite(6, LOW); + } + + if (SEV) { + VOL7 = 50/count+constrain(map(VA7, TH7, TH7+5000, 0, 65), 0, 65); + Insth.play(true); + Insth.setVolume(VOL7); +// Serial.print("Tone7 active at vol:"); +// Serial.println(VOL7); +// Serial.println(VA7); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(7, HIGH); + } + else if (!CV) { + digitalWrite(7, LOW); + } + } + + if (!SEV) { + Insth.pause (true); + + //Kill ControlVoltage + digitalWrite(7, LOW); + } + + + if (EIG) { + VOL8 = 50/count+constrain(map(VA8, TH8, TH8+5000, 0, 65), 0, 65); + Insti.play(true); + Insti.setVolume(VOL8); +// Serial.print("Tone8 active at vol:"); +// Serial.println(VOL8); +// Serial.println(VA8); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(8, HIGH); + } + else if (!CV) { + digitalWrite(8, LOW); + } + } + + if (!EIG) { + Insti.pause (true); + + //Kill ControlVoltage + digitalWrite(8, LOW); + } + + if (NIN) { + VOL9 = 50/count+constrain(map(VA9, TH9, TH9+5000, 0, 65), 0, 65); + Instj.play(true); + Instj.setVolume(VOL9); +// Serial.print("Tone9 active at vol:"); +// Serial.println(VOL9); +// Serial.println(VA9); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(9, HIGH); + } + else if (!CV) { + digitalWrite(9, LOW); + } + } + + if (!NIN) { + Instk.pause (true); + + //Kill ControlVoltage + digitalWrite(9, LOW); + } + + if (TEN) { + VOL10 = 50/count+constrain(map(VA10, TH10, TH10+5000, 0, 65), 0, 65); + Instk.play(true); + Instk.setVolume(VOL10); +// Serial.print("Tone10 active at vol:"); +// Serial.println(VOL10); +// Serial.println(VA10); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(10, HIGH); + } + else if (!CV) { + digitalWrite(10, LOW); + } + } + + if (!TEN) { + Instk.pause (true); + + //Kill ControlVoltage + digitalWrite(10, LOW); + } + + if (ELE) { + VOL11 = 50/count+constrain(map(VA11, TH11, TH11+5000, 0, 65), 0, 65); + Instl.play(true); + Instl.setVolume(VOL11); +// Serial.print("Tone11 active at vol:"); +// Serial.println(VOL11); +// Serial.println(VA11); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(11, HIGH); + } + else if (!CV) { + digitalWrite(11, LOW); + } + } + + if (!ELE) { + Instl.pause (true); + + //Kill ControlVoltage + digitalWrite(11, LOW); + } + + if (TWE) { + VOL12 = 50/count+constrain(map(VA12, TH12, TH12+5000, 0, 65), 0, 65); + Instm.play(true); + Instm.setVolume(VOL12); +// Serial.print("Tone12 active at vol:"); +// Serial.println(VOL12); +// Serial.println(VA12); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(12, HIGH); + } + else if (!CV) { + digitalWrite(12, LOW); + } + } + + if (!TWE) { + Instm.pause (true); + + //Kill ControlVoltage + digitalWrite(12, LOW); + } + + if (THT) { + VOL13 = 50/count+constrain(map(VA13, TH13, TH13+5000, 0, 65), 0, 65); + Instn.play(true); + Instn.setVolume(VOL13); +// Serial.print("Tone13 active at vol:"); +// Serial.println(VOL13); +// Serial.println(VA13); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(13, HIGH); + } + else if (!CV) { + digitalWrite(13, LOW); + } + } + + if (!THT) { + Instn.pause (true); + + //Kill ControlVoltage + digitalWrite(13, LOW); + } + + if (FOT) { + VOL14 = 50/count+constrain(map(VA14, TH14, TH14+5000, 0, 65), 0, 65); + Insto.play(true); + Insto.setVolume(VOL14); +// Serial.print("Tone14 active at vol:"); +// Serial.println(VOL14); +// Serial.println(VA14); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(14, HIGH); + } + else if (!CV) { + digitalWrite(14, LOW); + } + } + + if (!FOT) { + Insto.pause (true); + + //Kill ControlVoltage + digitalWrite(14, LOW); + } + + + if (FIT) { + VOL15 = 50/count+constrain(map(VA15, TH15, TH15+5000, 0, 65), 0, 65); + Instp.play(true); + Instp.setVolume(VOL15); +// Serial.print("Tone15 active at vol:"); +// Serial.println(VOL15); +// Serial.println(VA15); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(15, HIGH); + } + else if (!CV) { + digitalWrite(15, LOW); + } + } + + if (!FIT) { + Instp.pause (true); + + //Kill ControlVoltage + digitalWrite(15, LOW); + } +} diff --git a/sketches/max_sketch/muziek_zonder_pit_2.1/muziek_zonder_pit_2.1.ino b/sketches/max_sketch/muziek_zonder_pit_2.1/muziek_zonder_pit_2.1.ino new file mode 100644 index 0000000..c397ff6 --- /dev/null +++ b/sketches/max_sketch/muziek_zonder_pit_2.1/muziek_zonder_pit_2.1.ino @@ -0,0 +1,747 @@ +#include +#include +#include + +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + + +//note values +const char note0[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note1[] PROGMEM = ":d=128,b=300:d-1+"; //plays d4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:a-1+"; //plays a4 +const char note5[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note6[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note7[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:c+1+"; //plays c6 +const char note11[] PROGMEM = ":d=128,b=300:d+1+"; //plays d6 +const char note12[] PROGMEM = ":d=128,b=300:e+1+"; //plays e6 +const char note13[] PROGMEM = ":d=128,b=300:g+1+"; //plays g6 +const char note14[] PROGMEM = ":d=128,b=300:a+1+"; //plays a6 +const char note15[] PROGMEM = ":d=128,b=300:c+2+"; //plays c7 + +//instruments +MusicWithoutDelay Insta(note0); +MusicWithoutDelay Instb(note1); +MusicWithoutDelay Instc(note2); +MusicWithoutDelay Instd(note3); +MusicWithoutDelay Inste(note4); +MusicWithoutDelay Instf(note5); +MusicWithoutDelay Instg(note6); +MusicWithoutDelay Insth(note7); +MusicWithoutDelay Insti(note8); +MusicWithoutDelay Instj(note9); +MusicWithoutDelay Instk(note10); +MusicWithoutDelay Instl(note11); +MusicWithoutDelay Instm(note12); +MusicWithoutDelay Instn(note13); +MusicWithoutDelay Insto(note14); +MusicWithoutDelay Instp(note15); + + + + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9, VA10, VA11, VA12, VA13, VA14, VA15; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9, TH10, TH11, TH12, TH13, TH14, TH15; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9, VOL10, VOL11, VOL12, VOL13, VOL14, VOL15; +bool CV; + +int ZER; +int ONE; +int TWO; +int THR; +int FOU; +int FIV; +int SIX; +int SEV; +int EIG; +int NIN; +int TEN; +int ELE; +int TWE; +int THT; +int FOT; +int FIT; + +void setup() { + Serial.begin(115200); + + //set the gain for multiplexed INs + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + Serial.println("Ini MPX "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("MPX Ini"); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + calib(); + + Insta.begin(CHA, TRIANGLE, ENVELOPE2, 0); + Instb.begin(TRIANGLE, ENVELOPE2, 0); + Instc.begin(TRIANGLE, ENVELOPE2, 0); + Instd.begin(TRIANGLE, ENVELOPE2, 0); + Inste.begin(TRIANGLE, ENVELOPE2, 0); + Instf.begin(TRIANGLE, ENVELOPE2, 0); + Instg.begin(TRIANGLE, ENVELOPE2, 0); + Insth.begin(TRIANGLE, ENVELOPE2, 0); + Insti.begin(TRIANGLE, ENVELOPE2, 0); + Instj.begin(TRIANGLE, ENVELOPE2, 0); + Instk.begin(TRIANGLE, ENVELOPE2, 0); + Instl.begin(TRIANGLE, ENVELOPE2, 0); + Instm.begin(TRIANGLE, ENVELOPE2, 0); + Instn.begin(TRIANGLE, ENVELOPE2, 0); + Insto.begin(TRIANGLE, ENVELOPE2, 0); + Instp.begin(TRIANGLE, ENVELOPE2, 0); + + Insta.pause(true); + Instb.pause(true); + Instc.pause(true); + Instd.pause(true); + Inste.pause(true); + Instf.pause(true); + Instg.pause(true); + Insth.pause(true); + Insti.pause(true); + Instj.pause(true); + Instk.pause(true); + Instl.pause(true); + Instm.pause(true); + Instn.pause(true); + Insto.pause(true); + Instp.pause(true); + + Serial.println("go!"); +} + +void calib() { + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (adsa.readADC_SingleEnded(0) + 800); + TH1 = (adsa.readADC_SingleEnded(1) + 800); + TH2 = (adsa.readADC_SingleEnded(2) + 800); + TH3 = (adsa.readADC_SingleEnded(3) + 800); + TH4 = (adsb.readADC_SingleEnded(0) + 800); + TH5 = (adsb.readADC_SingleEnded(1) + 800); + TH6 = (adsb.readADC_SingleEnded(2) + 800); + TH7 = (adsb.readADC_SingleEnded(3) + 800); + TH8 = (adsc.readADC_SingleEnded(0) + 800); + TH9 = (adsc.readADC_SingleEnded(1) + 800); + TH10 = (adsc.readADC_SingleEnded(2) + 800); + TH11 = (adsc.readADC_SingleEnded(3) + 800); + TH12 = (adsd.readADC_SingleEnded(0) + 800); + TH13 = (adsd.readADC_SingleEnded(1) + 800); + TH14 = (adsd.readADC_SingleEnded(2) + 800); + TH15 = (adsd.readADC_SingleEnded(3) + 800); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + Serial.print ("TH10="); + Serial.println (TH10); + Serial.print ("TH11="); + Serial.println (TH11); + Serial.print ("TH12="); + Serial.println (TH12); + Serial.print ("TH13="); + Serial.println (TH13); + Serial.print ("TH14="); + Serial.println (TH14); + Serial.print ("TH15="); + Serial.println (TH15); + } + +void loop() { + CV = digitalRead(17); + count = 0; + + Insta.update(); + Instb.update(); + Instc.update(); + Instd.update(); + Inste.update(); + Instf.update(); + Instg.update(); + Insth.update(); + Insti.update(); + Instj.update(); + Instk.update(); + Instl.update(); + Instm.update(); + Instn.update(); + Insto.update(); + Instp.update(); + + + //Messure LDR inputs + VA0 = adsa.readADC_SingleEnded(0); + VA1 = adsa.readADC_SingleEnded(1); + VA2 = adsa.readADC_SingleEnded(2); + VA3 = adsa.readADC_SingleEnded(3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = adsb.readADC_SingleEnded(0); + VA5 = adsb.readADC_SingleEnded(1); + VA6 = adsb.readADC_SingleEnded(2); + VA7 = adsb.readADC_SingleEnded(3); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = adsc.readADC_SingleEnded(0); + VA9 = adsc.readADC_SingleEnded(1); + VA10 = adsc.readADC_SingleEnded(2); + VA11 = adsc.readADC_SingleEnded(3); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.print("VA10: "); Serial.println(VA10); +// Serial.print("VA11: "); Serial.println(VA11); +// Serial.println(" "); + + VA12 = adsd.readADC_SingleEnded(0); + VA13 = adsd.readADC_SingleEnded(1); + VA14 = adsd.readADC_SingleEnded(2); + VA15 = adsd.readADC_SingleEnded(3); + +// Serial.print("VA12: "); Serial.println(VA12); +// Serial.print("VA13: "); Serial.println(VA13); +// Serial.print("VA14: "); Serial.println(VA14); +// Serial.print("VA15: "); Serial.println(VA15); +// Serial.println(" "); + + + + if (VA0 > TH0) { + count++; + ZER = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(0, HIGH); + } + else if (!CV) { + digitalWrite(0, LOW); + } + } + else if (VA0 < TH0) { + ZER = false; + //Kill ControlVoltage + digitalWrite(0, LOW); + } + + if (VA1 > TH1) { + count++; + ONE = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(1, HIGH); + } + else if (!CV) { + digitalWrite(1, LOW); + } + } + else if (VA1 < TH1) { + ONE = false; + //Kill ControlVoltage + digitalWrite(1, LOW); + } + + if (VA2 > TH2) { + count++; + TWO = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(2, HIGH); + } + else if (!CV) { + digitalWrite(2, LOW); + } + } + else if (VA2 < TH2) { + TWO = false; + //Kill ControlVoltage + digitalWrite(2, LOW); + } + + if (VA3 > TH3) { + count++; + THR = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(4, HIGH); + } + else if (!CV) { + digitalWrite(4, LOW); + } + } + else if (VA3 < TH3) { + THR = false; + //Kill ControlVoltage + digitalWrite(4, LOW); + } + + if (VA4 > TH4) { + count++; + FOU = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(5, HIGH); + } + else if (!CV) { + digitalWrite(5, LOW); + } + } + else if (VA4 < TH4) { + FOU = false; + //Kill ControlVoltage + digitalWrite(5, LOW); + } + + if (VA5 > TH5) { + count++; + FIV = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(6, HIGH); + } + else if (!CV) { + digitalWrite(6, LOW); + } + } + else if (VA5 < TH5) { + FIV = false; + //Kill ControlVoltage + digitalWrite(6, LOW); + } + + if (VA6 > TH6) { + count++; + SIX = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(7, HIGH); + } + else if (!CV) { + digitalWrite(7, LOW); + } + } + else if (VA6 < TH6) { + SIX = false; + //Kill ControlVoltage + digitalWrite(7, LOW); + } + + if (VA7 > TH7) { + count++; + SEV = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(8, HIGH); + } + else if (!CV) { + digitalWrite(8, LOW); + } + } + else if (VA7 < TH7) { + SEV = false; + //Kill ControlVoltage + digitalWrite(8, LOW); + } + + if (VA8 > TH8) { + count++; + EIG = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(9, HIGH); + } + else if (!CV) { + digitalWrite(9, LOW); + } + } + else if (VA8 < TH8) { + EIG = false; + //Kill ControlVoltage + digitalWrite(9, LOW); + } + + if (VA9 > TH9) { + count++; + NIN = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(10, HIGH); + } + else if (!CV) { + digitalWrite(10, LOW); + } + } + else if (VA9 < TH9) { + NIN = false; + //Kill ControlVoltage + digitalWrite(10, LOW); + } + + if (VA10 > TH10) { + count++; + TEN = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(11, HIGH); + } + else if (!CV) { + digitalWrite(11, LOW); + } + } + else if (VA10 < TH10) { + TEN = false; + //Kill ControlVoltage + digitalWrite(11, LOW); + } + + if (VA11 > TH11) { + count++; + ELE = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(12, HIGH); + } + else if (!CV) { + digitalWrite(12, LOW); + } + } + else if (VA11 < TH11) { + ELE = false; + //Kill ControlVoltage + digitalWrite(12, LOW); + } + + if (VA12 > TH12) { + count++; + TWE = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(13, HIGH); + } + else if (!CV) { + digitalWrite(13, LOW); + } + } + else if (VA12 < TH12) { + TWE = false; + //Kill ControlVoltage + digitalWrite(13, LOW); + } + + if (VA13 > TH13) { + count++; + THT = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(14, HIGH); + } + else if (!CV) { + digitalWrite(14, LOW); + } + } + else if (VA13 < TH13) { + THT = false; + //Kill ControlVoltage + digitalWrite(14, LOW); + } + + if (VA14 > TH14) { + count++; + FOT = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(15, HIGH); + } + else if (!CV) { + digitalWrite(15, LOW); + } + } + else if (VA14 < TH14) { + FOT = false; + //Kill ControlVoltage + digitalWrite(15, LOW); + } + + if (VA15 > TH15) { + count++; + FIT = true; + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(16, HIGH); + } + else if (!CV) { + digitalWrite(16, LOW); + } + } + else if (VA15 < TH15) { + FIT = false; + //Kill ControlVoltage + digitalWrite(16, LOW); + } + + +// Serial.print("Intruments playing = "); +// Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + VOL0 = 50/count+constrain(map(VA0, TH0, TH0+5000, 0, 65), 0, 65); + Insta.play(true); + Insta.setVolume(VOL0); +// Serial.print("Tone0 active at vol:"); +// Serial.println(VOL0); +// Serial.println(VA0); + } + + if (!ZER) { + Insta.pause (true); + } + + if (ONE) { + VOL1 = 50/count+constrain(map(VA1, TH1, TH1+5000, 0, 65), 0, 65); + Instb.play(true); + Instb.setVolume(VOL1); +// Serial.print("Tone1 active at vol:"); +// Serial.println(VOL1); +// Serial.println(VA1); + } + + if (!ONE) { + Instb.pause (true); + } + + if (TWO) { + VOL2 = 50/count+constrain(map(VA2, TH2, TH2+5000, 0, 65), 0, 65); + Instc.play(true); + Instc.setVolume(VOL2); +// Serial.print("Tone2 active at vol:"); +// Serial.println(VOL2); +// Serial.println(VA2); + } + + if (!TWO) { + Instc.pause (true); + } + + if (THR) { + VOL3 = 50/count+constrain(map(VA3, TH3, TH3+5000, 0, 65), 0, 65); + Instd.play(true); + Instd.setVolume(VOL3); +// Serial.print("Tone3 active at vol:"); +// Serial.println(VOL3); +// Serial.println(VA3); + } + + if (!THR) { + Instd.pause (true); + } + + if (FOU) { + VOL4 = 50/count+constrain(map(VA4, TH4, TH4+5000, 0, 65), 0, 65); + Inste.play(true); + Inste.setVolume(VOL4); +// Serial.print("Tone4 active at vol:"); +// Serial.println(VOL4); +// Serial.println(VA4); + } + + if (!FOU) { + Inste.pause (true); + } + + if (FIV) { + VOL5 = 50/count+constrain(map(VA5, TH5, TH5+5000, 0, 65), 0, 65); + Instf.play(true); + Instf.setVolume(VOL5); +// Serial.print("Tone5 active at vol:"); +// Serial.println(VOL5); +// Serial.println(VA5); + } + + if (!FIV) { + Instf.pause (true); + } + + + if (SIX) { + VOL6 = 50/count+constrain(map(VA6, TH6, TH6+5000, 0, 65), 0, 65); + Instg.play(true); + Instg.setVolume(VOL6); +// Serial.print("Tone6 active at vol:"); +// Serial.println(VOL6); +// Serial.println(VA6); + } + + if (!SIX) { + Instg.pause (true); + } + + if (SEV) { + VOL7 = 50/count+constrain(map(VA7, TH7, TH7+5000, 0, 65), 0, 65); + Insth.play(true); + Insth.setVolume(VOL7); +// Serial.print("Tone7 active at vol:"); +// Serial.println(VOL7); +// Serial.println(VA7); + } + + if (!SEV) { + Insth.pause (true); + } + + + if (EIG) { + VOL8 = 50/count+constrain(map(VA8, TH8, TH8+5000, 0, 65), 0, 65); + Insti.play(true); + Insti.setVolume(VOL8); +// Serial.print("Tone8 active at vol:"); +// Serial.println(VOL8); +// Serial.println(VA8); + } + + if (!EIG) { + Insti.pause (true); + } + + if (NIN) { + VOL9 = 50/count+constrain(map(VA9, TH9, TH9+5000, 0, 65), 0, 65); + Instj.play(true); + Instj.setVolume(VOL9); +// Serial.print("Tone9 active at vol:"); +// Serial.println(VOL9); +// Serial.println(VA9); + } + + if (!NIN) { + Instk.pause (true); + } + + if (TEN) { + VOL10 = 50/count+constrain(map(VA10, TH10, TH10+5000, 0, 65), 0, 65); + Instk.play(true); + Instk.setVolume(VOL10); +// Serial.print("Tone10 active at vol:"); +// Serial.println(VOL10); +// Serial.println(VA10); + } + + if (!TEN) { + Instk.pause (true); + } + + if (ELE) { + VOL11 = 50/count+constrain(map(VA11, TH11, TH11+5000, 0, 65), 0, 65); + Instl.play(true); + Instl.setVolume(VOL11); +// Serial.print("Tone11 active at vol:"); +// Serial.println(VOL11); +// Serial.println(VA11); + } + + if (!ELE) { + Instl.pause (true); + } + + if (TWE) { + VOL12 = 50/count+constrain(map(VA12, TH12, TH12+5000, 0, 65), 0, 65); + Instm.play(true); + Instm.setVolume(VOL12); +// Serial.print("Tone12 active at vol:"); +// Serial.println(VOL12); +// Serial.println(VA12); + + } + + if (!TWE) { + Instm.pause (true); + } + + if (THT) { + VOL13 = 50/count+constrain(map(VA13, TH13, TH13+5000, 0, 65), 0, 65); + Instn.play(true); + Instn.setVolume(VOL13); +// Serial.print("Tone13 active at vol:"); +// Serial.println(VOL13); +// Serial.println(VA13); + } + + if (!THT) { + Instn.pause (true); + } + + if (FOT) { + VOL14 = 50/count+constrain(map(VA14, TH14, TH14+5000, 0, 65), 0, 65); + Insto.play(true); + Insto.setVolume(VOL14); +// Serial.print("Tone14 active at vol:"); +// Serial.println(VOL14); +// Serial.println(VA14); + } + + if (!FOT) { + Insto.pause (true); + } + + + if (FIT) { + VOL15 = 50/count+constrain(map(VA15, TH15, TH15+5000, 0, 65), 0, 65); + Instp.play(true); + Instp.setVolume(VOL15); +// Serial.print("Tone15 active at vol:"); +// Serial.println(VOL15); +// Serial.println(VA15); + } + + if (!FIT) { + Instp.pause (true); + } +} diff --git a/sketches/max_sketch/muziek_zonder_pit_2.2/muziek_zonder_pit_2.2.ino b/sketches/max_sketch/muziek_zonder_pit_2.2/muziek_zonder_pit_2.2.ino new file mode 100644 index 0000000..5c5647a --- /dev/null +++ b/sketches/max_sketch/muziek_zonder_pit_2.2/muziek_zonder_pit_2.2.ino @@ -0,0 +1,766 @@ +#include +#include +#include + +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + + +//note values +const char note0[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note1[] PROGMEM = ":d=128,b=300:d-1+"; //plays d4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:a-1+"; //plays a4 +const char note5[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note6[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note7[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:c+1+"; //plays c6 +const char note11[] PROGMEM = ":d=128,b=300:d+1+"; //plays d6 +const char note12[] PROGMEM = ":d=128,b=300:e+1+"; //plays e6 +const char note13[] PROGMEM = ":d=128,b=300:g+1+"; //plays g6 +const char note14[] PROGMEM = ":d=128,b=300:a+1+"; //plays a6 +const char note15[] PROGMEM = ":d=128,b=300:c+2+"; //plays c7 + +//instruments +MusicWithoutDelay Insta(note0); +MusicWithoutDelay Instb(note1); +MusicWithoutDelay Instc(note2); +MusicWithoutDelay Instd(note3); +MusicWithoutDelay Inste(note4); +MusicWithoutDelay Instf(note5); +MusicWithoutDelay Instg(note6); +MusicWithoutDelay Insth(note7); +MusicWithoutDelay Insti(note8); +MusicWithoutDelay Instj(note9); +MusicWithoutDelay Instk(note10); +MusicWithoutDelay Instl(note11); +MusicWithoutDelay Instm(note12); +MusicWithoutDelay Instn(note13); +MusicWithoutDelay Insto(note14); +MusicWithoutDelay Instp(note15); + + + + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9, VA10, VA11, VA12, VA13, VA14, VA15; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9, TH10, TH11, TH12, TH13, TH14, TH15; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9, VOL10, VOL11, VOL12, VOL13, VOL14, VOL15; +bool CV; + +int ZER; +int ONE; +int TWO; +int THR; +int FOU; +int FIV; +int SIX; +int SEV; +int EIG; +int NIN; +int TEN; +int ELE; +int TWE; +int THT; +int FOT; +int FIT; + +void setup() { + Serial.begin(115200); + + //set the gain for multiplexed INs + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + Serial.println("Ini MPX "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("MPX Ini"); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + calib(); + + Insta.begin(CHA, TRIANGLE, ENVELOPE2, 0); + Instb.begin(TRIANGLE, ENVELOPE2, 0); + Instc.begin(TRIANGLE, ENVELOPE2, 0); + Instd.begin(TRIANGLE, ENVELOPE2, 0); + Inste.begin(TRIANGLE, ENVELOPE2, 0); + Instf.begin(TRIANGLE, ENVELOPE2, 0); + Instg.begin(TRIANGLE, ENVELOPE2, 0); + Insth.begin(TRIANGLE, ENVELOPE2, 0); + Insti.begin(TRIANGLE, ENVELOPE2, 0); + Instj.begin(TRIANGLE, ENVELOPE2, 0); + Instk.begin(TRIANGLE, ENVELOPE2, 0); + Instl.begin(TRIANGLE, ENVELOPE2, 0); + Instm.begin(TRIANGLE, ENVELOPE2, 0); + Instn.begin(TRIANGLE, ENVELOPE2, 0); + Insto.begin(TRIANGLE, ENVELOPE2, 0); + Instp.begin(TRIANGLE, ENVELOPE2, 0); + + Insta.pause(true); + Instb.pause(true); + Instc.pause(true); + Instd.pause(true); + Inste.pause(true); + Instf.pause(true); + Instg.pause(true); + Insth.pause(true); + Insti.pause(true); + Instj.pause(true); + Instk.pause(true); + Instl.pause(true); + Instm.pause(true); + Instn.pause(true); + Insto.pause(true); + Instp.pause(true); + + Serial.println("go!"); +} + +void calib() { + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (adsa.readADC_SingleEnded(0) + 800); + TH1 = (adsa.readADC_SingleEnded(1) + 800); + TH2 = (adsa.readADC_SingleEnded(2) + 800); + TH3 = (adsa.readADC_SingleEnded(3) + 800); + TH4 = (adsb.readADC_SingleEnded(0) + 800); + TH5 = (adsb.readADC_SingleEnded(1) + 800); + TH6 = (adsb.readADC_SingleEnded(2) + 800); + TH7 = (adsb.readADC_SingleEnded(3) + 800); + TH8 = (adsc.readADC_SingleEnded(0) + 800); + TH9 = (adsc.readADC_SingleEnded(1) + 800); + TH10 = (adsc.readADC_SingleEnded(2) + 800); + TH11 = (adsc.readADC_SingleEnded(3) + 800); + TH12 = (adsd.readADC_SingleEnded(0) + 800); + TH13 = (adsd.readADC_SingleEnded(1) + 800); + TH14 = (adsd.readADC_SingleEnded(2) + 800); + TH15 = (adsd.readADC_SingleEnded(3) + 800); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + Serial.print ("TH10="); + Serial.println (TH10); + Serial.print ("TH11="); + Serial.println (TH11); + Serial.print ("TH12="); + Serial.println (TH12); + Serial.print ("TH13="); + Serial.println (TH13); + Serial.print ("TH14="); + Serial.println (TH14); + Serial.print ("TH15="); + Serial.println (TH15); + } + +void loop() { + CV = digitalRead(20); + count = 0; + + Insta.update(); + Instb.update(); + Instc.update(); + Instd.update(); + Inste.update(); + Instf.update(); + Instg.update(); + Insth.update(); + Insti.update(); + Instj.update(); + Instk.update(); + Instl.update(); + Instm.update(); + Instn.update(); + Insto.update(); + Instp.update(); + + + //Messure LDR inputs + VA0 = adsa.readADC_SingleEnded(0); + VA1 = adsa.readADC_SingleEnded(1); + VA2 = adsa.readADC_SingleEnded(2); + VA3 = adsa.readADC_SingleEnded(3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = adsb.readADC_SingleEnded(0); + VA5 = adsb.readADC_SingleEnded(1); + VA6 = adsb.readADC_SingleEnded(2); + VA7 = adsb.readADC_SingleEnded(3); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = adsc.readADC_SingleEnded(0); + VA9 = adsc.readADC_SingleEnded(1); + VA10 = adsc.readADC_SingleEnded(2); + VA11 = adsc.readADC_SingleEnded(3); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.print("VA10: "); Serial.println(VA10); +// Serial.print("VA11: "); Serial.println(VA11); +// Serial.println(" "); + + VA12 = adsd.readADC_SingleEnded(0); + VA13 = adsd.readADC_SingleEnded(1); + VA14 = adsd.readADC_SingleEnded(2); + VA15 = adsd.readADC_SingleEnded(3); + +// Serial.print("VA12: "); Serial.println(VA12); +// Serial.print("VA13: "); Serial.println(VA13); +// Serial.print("VA14: "); Serial.println(VA14); +// Serial.print("VA15: "); Serial.println(VA15); +// Serial.println(" "); + + + + if (VA0 > TH0 && !CV) { + count++; + ZER = true; + digitalWrite(0, LOW); + } + + else if (VA0 > TH0 && CV) { + ZER = false; + digitalWrite(0, HIGH); + } + + else if (VA0 < TH0) { + ZER = false; + digitalWrite(0, LOW); + } + + + + if (VA1 > TH1 && !CV) { + count++; + ONE = true; + digitalWrite(1, LOW); + } + + else if (VA1 > TH1 && CV) { + digitalWrite(1, HIGH); + ONE = false; + } + + else if (VA1 < TH1) { + ONE = false; + digitalWrite(1, LOW); + } + + + + if (VA2 > TH2 && !CV) { + count++; + TWO = true; + digitalWrite(2, LOW); + } + + else if (VA2 > TH2 && CV) { + TWO = false; + digitalWrite(2, HIGH); + } + + else if (VA2 < TH2) { + TWO = false; + digitalWrite(2, LOW); + } + + + + if (VA3 > TH3 && !CV) { + count++; + THR = true; + digitalWrite(4, LOW); + } + + else if (VA3 > TH3 && CV) { + THR = false; + digitalWrite(4, HIGH); + } + + else if (VA3 < TH3) { + THR = false; + digitalWrite(4, LOW); + } + + + + if (VA4 > TH4 && !CV) { + count++; + FOU = true; + digitalWrite(5, LOW); + } + + else if (VA4 > TH4 && CV) { + FOU = false; + digitalWrite(5, HIGH); + } + + else if (VA4 < TH4) { + FOU = false; + digitalWrite(5, LOW); + } + + + + if (VA5 > TH5 && !CV) { + count++; + FIV = true; + digitalWrite(6, LOW); + } + + else if (VA5 > TH5 && CV) { + FIV = false; + digitalWrite(6, HIGH); + } + + else if (VA5 < TH5) { + FIV = false; + digitalWrite(6, LOW); + } + + + + if (VA6 > TH6 && !CV) { + count++; + SIX = true; + digitalWrite(7, LOW); + } + + else if (VA6 > TH6 && CV) { + SIX = false; + digitalWrite(7, HIGH); + } + + else if (VA6 < TH6) { + SIX = false; + digitalWrite(7, LOW); + } + + + + if (VA7 > TH7 && !CV) { + count++; + SEV = true; + digitalWrite(8, LOW); + } + + else if (VA7 > TH7 && CV) { + SEV = false; + digitalWrite(8, HIGH); + } + + else if (VA7 < TH7) { + SEV = false; + digitalWrite(8, LOW); + } + + + + if (VA8 > TH8 && !CV) { + count++; + EIG = true; + digitalWrite(9, LOW); + } + + else if (VA8 > TH8 && CV) { + EIG = false; + digitalWrite(9, HIGH); + } + + else if (VA8 < TH8) { + EIG = false; + digitalWrite(9, LOW); + } + + + + if (VA9 > TH9 && !CV) { + count++; + NIN = true; + digitalWrite(10, LOW); + } + + else if (VA9 > TH9 && CV) { + NIN = false; + digitalWrite(10, HIGH); + } + + else if (VA9 < TH9) { + NIN = false; + digitalWrite(10, LOW); + } + + + + if (VA10 > TH10 && !CV) { + count++; + TEN = true; + digitalWrite(11, LOW); + } + + else if (VA10 > TH10 && CV) { + TEN = false; + digitalWrite(11, HIGH); + } + + else if (VA10 < TH10) { + TEN = false; + digitalWrite(11, LOW); + } + + + + if (VA11 > TH11 && !CV) { + count++; + ELE = true; + digitalWrite(12, LOW); + } + + else if (VA11 > TH11 && CV) { + ELE = false; + digitalWrite(12, HIGH); + } + + else if (VA11 < TH11) { + ELE = false; + digitalWrite(12, LOW); + } + + + + if (VA12 > TH12 && !CV) { + count++; + TWE = true; + digitalWrite(13, LOW); + } + + else if (VA12 > TH12 && CV) { + TWE = false; + digitalWrite(13, HIGH); + } + + else if (VA12 < TH12) { + TWE = false; + digitalWrite(13, LOW); + } + + + + if (VA13 > TH13 && !CV) { + count++; + THT = true; + digitalWrite(14, LOW); + } + + else if (VA13 > TH13 && CV) { + THT = false; + digitalWrite(14, HIGH); + } + + else if (VA13 < TH13) { + THT = false; + digitalWrite(14, LOW); + } + + + + if (VA14 > TH14 && !CV) { + count++; + FOT = true; + digitalWrite(15, LOW); + } + + else if (VA14 > TH14 && CV) { + FOT = false; + digitalWrite(15, HIGH); + } + + else if (VA14 < TH14) { + FOT = false; + digitalWrite(15, LOW); + } + + + + if (VA15 > TH15 && !CV) { + count++; + FIT = true; + digitalWrite(16, LOW); + } + + else if (VA15 > TH15 && CV) { + FIT = false; + digitalWrite(16, HIGH); + } + + else if (VA15 < TH15) { + FIT = false; + digitalWrite(16, LOW); + } + + + +// Serial.print("Intruments playing = "); +// Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + VOL0 = 50/count+constrain(map(VA0, TH0, TH0+5000, 0, 65), 0, 65); + Insta.play(true); + Insta.setVolume(VOL0); +// Serial.print("Tone0 active at vol:"); +// Serial.println(VOL0); +// Serial.println(VA0); + } + + if (!ZER) { + Insta.pause (true); + } + + if (ONE) { + VOL1 = 50/count+constrain(map(VA1, TH1, TH1+5000, 0, 65), 0, 65); + Instb.play(true); + Instb.setVolume(VOL1); +// Serial.print("Tone1 active at vol:"); +// Serial.println(VOL1); +// Serial.println(VA1); + } + + if (!ONE) { + Instb.pause (true); + } + + if (TWO) { + VOL2 = 50/count+constrain(map(VA2, TH2, TH2+5000, 0, 65), 0, 65); + Instc.play(true); + Instc.setVolume(VOL2); +// Serial.print("Tone2 active at vol:"); +// Serial.println(VOL2); +// Serial.println(VA2); + } + + if (!TWO) { + Instc.pause (true); + } + + if (THR) { + VOL3 = 50/count+constrain(map(VA3, TH3, TH3+5000, 0, 65), 0, 65); + Instd.play(true); + Instd.setVolume(VOL3); +// Serial.print("Tone3 active at vol:"); +// Serial.println(VOL3); +// Serial.println(VA3); + } + + if (!THR) { + Instd.pause (true); + } + + if (FOU) { + VOL4 = 50/count+constrain(map(VA4, TH4, TH4+5000, 0, 65), 0, 65); + Inste.play(true); + Inste.setVolume(VOL4); +// Serial.print("Tone4 active at vol:"); +// Serial.println(VOL4); +// Serial.println(VA4); + } + + if (!FOU) { + Inste.pause (true); + } + + if (FIV) { + VOL5 = 50/count+constrain(map(VA5, TH5, TH5+5000, 0, 65), 0, 65); + Instf.play(true); + Instf.setVolume(VOL5); +// Serial.print("Tone5 active at vol:"); +// Serial.println(VOL5); +// Serial.println(VA5); + } + + if (!FIV) { + Instf.pause (true); + } + + + if (SIX) { + VOL6 = 50/count+constrain(map(VA6, TH6, TH6+5000, 0, 65), 0, 65); + Instg.play(true); + Instg.setVolume(VOL6); +// Serial.print("Tone6 active at vol:"); +// Serial.println(VOL6); +// Serial.println(VA6); + } + + if (!SIX) { + Instg.pause (true); + } + + if (SEV) { + VOL7 = 50/count+constrain(map(VA7, TH7, TH7+5000, 0, 65), 0, 65); + Insth.play(true); + Insth.setVolume(VOL7); +// Serial.print("Tone7 active at vol:"); +// Serial.println(VOL7); +// Serial.println(VA7); + } + + if (!SEV) { + Insth.pause (true); + } + + + if (EIG) { + VOL8 = 50/count+constrain(map(VA8, TH8, TH8+5000, 0, 65), 0, 65); + Insti.play(true); + Insti.setVolume(VOL8); +// Serial.print("Tone8 active at vol:"); +// Serial.println(VOL8); +// Serial.println(VA8); + } + + if (!EIG) { + Insti.pause (true); + } + + if (NIN) { + VOL9 = 50/count+constrain(map(VA9, TH9, TH9+5000, 0, 65), 0, 65); + Instj.play(true); + Instj.setVolume(VOL9); +// Serial.print("Tone9 active at vol:"); +// Serial.println(VOL9); +// Serial.println(VA9); + } + + if (!NIN) { + Instk.pause (true); + } + + if (TEN) { + VOL10 = 50/count+constrain(map(VA10, TH10, TH10+5000, 0, 65), 0, 65); + Instk.play(true); + Instk.setVolume(VOL10); +// Serial.print("Tone10 active at vol:"); +// Serial.println(VOL10); +// Serial.println(VA10); + } + + if (!TEN) { + Instk.pause (true); + } + + if (ELE) { + VOL11 = 50/count+constrain(map(VA11, TH11, TH11+5000, 0, 65), 0, 65); + Instl.play(true); + Instl.setVolume(VOL11); +// Serial.print("Tone11 active at vol:"); +// Serial.println(VOL11); +// Serial.println(VA11); + } + + if (!ELE) { + Instl.pause (true); + } + + if (TWE) { + VOL12 = 50/count+constrain(map(VA12, TH12, TH12+5000, 0, 65), 0, 65); + Instm.play(true); + Instm.setVolume(VOL12); +// Serial.print("Tone12 active at vol:"); +// Serial.println(VOL12); +// Serial.println(VA12); + + } + + if (!TWE) { + Instm.pause (true); + } + + if (THT) { + VOL13 = 50/count+constrain(map(VA13, TH13, TH13+5000, 0, 65), 0, 65); + Instn.play(true); + Instn.setVolume(VOL13); +// Serial.print("Tone13 active at vol:"); +// Serial.println(VOL13); +// Serial.println(VA13); + } + + if (!THT) { + Instn.pause (true); + } + + if (FOT) { + VOL14 = 50/count+constrain(map(VA14, TH14, TH14+5000, 0, 65), 0, 65); + Insto.play(true); + Insto.setVolume(VOL14); +// Serial.print("Tone14 active at vol:"); +// Serial.println(VOL14); +// Serial.println(VA14); + } + + if (!FOT) { + Insto.pause (true); + } + + + if (FIT) { + VOL15 = 50/count+constrain(map(VA15, TH15, TH15+5000, 0, 65), 0, 65); + Instp.play(true); + Instp.setVolume(VOL15); +// Serial.print("Tone15 active at vol:"); +// Serial.println(VOL15); +// Serial.println(VA15); + } + + if (!FIT) { + Instp.pause (true); + } + + if (digitalRead(17) == HIGH) { + calib(); + } +} diff --git a/sketches/max_sketch/muziek_zonder_pit_2/muziek_zonder_pit_2.ino b/sketches/max_sketch/muziek_zonder_pit_2/muziek_zonder_pit_2.ino new file mode 100644 index 0000000..18e0f8f --- /dev/null +++ b/sketches/max_sketch/muziek_zonder_pit_2/muziek_zonder_pit_2.ino @@ -0,0 +1,776 @@ +#include +#include +#include + +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + + +//note values +const char note0[] PROGMEM = ":d=128,b=300:c-1+"; //plays c4 +const char note1[] PROGMEM = ":d=128,b=300:d-1+"; //plays d4 +const char note2[] PROGMEM = ":d=128,b=300:e-1+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=300:g-1+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=300:a-1+"; //plays a4 +const char note5[] PROGMEM = ":d=128,b=300:c+"; //plays c5 +const char note6[] PROGMEM = ":d=128,b=300:d+"; //plays d5 +const char note7[] PROGMEM = ":d=128,b=300:e+"; //plays e5 +const char note8[] PROGMEM = ":d=128,b=300:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=300:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=300:c+1+"; //plays c6 +const char note11[] PROGMEM = ":d=128,b=300:d+1+"; //plays d6 +const char note12[] PROGMEM = ":d=128,b=300:e+1+"; //plays e6 +const char note13[] PROGMEM = ":d=128,b=300:g+1+"; //plays g6 +const char note14[] PROGMEM = ":d=128,b=300:a+1+"; //plays a6 +const char note15[] PROGMEM = ":d=128,b=300:c+2+"; //plays c7 + +//instruments +MusicWithoutDelay Insta(note0); +MusicWithoutDelay Instb(note1); +MusicWithoutDelay Instc(note2); +MusicWithoutDelay Instd(note3); +MusicWithoutDelay Inste(note4); +MusicWithoutDelay Instf(note5); +MusicWithoutDelay Instg(note6); +MusicWithoutDelay Insth(note7); +MusicWithoutDelay Insti(note8); +MusicWithoutDelay Instj(note9); +MusicWithoutDelay Instk(note10); +MusicWithoutDelay Instl(note11); +MusicWithoutDelay Instm(note12); +MusicWithoutDelay Instn(note13); +MusicWithoutDelay Insto(note14); +MusicWithoutDelay Instp(note15); + + + + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9, VA10, VA11, VA12, VA13, VA14, VA15; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9, TH10, TH11, TH12, TH13, TH14, TH15; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9, VOL10, VOL11, VOL12, VOL13, VOL14, VOL15; +bool CV; + +bool ZER; +bool ONE; +bool TWO; +bool THR; +bool FOU; +bool FIV; +bool SIX; +bool SEV; +bool EIG; +bool NIN; +bool TEN; +bool ELE; +bool TWE; +bool THT; +bool FOT; +bool FIT; + +void setup() { + Serial.begin(115200); + + //set the gain for multiplexed INs + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + Serial.println("Ini MPX "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("MPX Ini"); + + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (adsa.readADC_SingleEnded(0) + 800); + TH1 = (adsa.readADC_SingleEnded(1) + 800); + TH2 = (adsa.readADC_SingleEnded(2) + 800); + TH3 = (adsa.readADC_SingleEnded(3) + 800); + TH4 = (adsb.readADC_SingleEnded(0) + 800); + TH5 = (adsb.readADC_SingleEnded(1) + 800); + TH6 = (adsb.readADC_SingleEnded(2) + 800); + TH7 = (adsb.readADC_SingleEnded(3) + 800); + TH8 = (adsc.readADC_SingleEnded(0) + 800); + TH9 = (adsc.readADC_SingleEnded(1) + 800); + TH10 = (adsc.readADC_SingleEnded(2) + 800); + TH11 = (adsc.readADC_SingleEnded(3) + 800); + TH12 = (adsd.readADC_SingleEnded(0) + 800); + TH13 = (adsd.readADC_SingleEnded(1) + 800); + TH14 = (adsd.readADC_SingleEnded(2) + 800); + TH15 = (adsd.readADC_SingleEnded(3) + 800); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + Serial.print ("TH10="); + Serial.println (TH10); + Serial.print ("TH11="); + Serial.println (TH11); + Serial.print ("TH12="); + Serial.println (TH12); + Serial.print ("TH13="); + Serial.println (TH13); + Serial.print ("TH14="); + Serial.println (TH14); + Serial.print ("TH15="); + Serial.println (TH15); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + Insta.begin(CHA, TRIANGLE, ENVELOPE2, 0); + Instb.begin(TRIANGLE, ENVELOPE2, 0); + Instc.begin(TRIANGLE, ENVELOPE2, 0); + Instd.begin(TRIANGLE, ENVELOPE2, 0); + Inste.begin(TRIANGLE, ENVELOPE2, 0); + Instf.begin(TRIANGLE, ENVELOPE2, 0); + Instg.begin(TRIANGLE, ENVELOPE2, 0); + Insth.begin(TRIANGLE, ENVELOPE2, 0); + Insti.begin(TRIANGLE, ENVELOPE2, 0); + Instj.begin(TRIANGLE, ENVELOPE2, 0); + Instk.begin(TRIANGLE, ENVELOPE2, 0); + Instl.begin(TRIANGLE, ENVELOPE2, 0); + Instm.begin(TRIANGLE, ENVELOPE2, 0); + Instn.begin(TRIANGLE, ENVELOPE2, 0); + Insto.begin(TRIANGLE, ENVELOPE2, 0); + Instp.begin(TRIANGLE, ENVELOPE2, 0); + + Insta.pause(true); + Instb.pause(true); + Instc.pause(true); + Instd.pause(true); + Inste.pause(true); + Instf.pause(true); + Instg.pause(true); + Insth.pause(true); + Insti.pause(true); + Instj.pause(true); + Instk.pause(true); + Instl.pause(true); + Instm.pause(true); + Instn.pause(true); + Insto.pause(true); + Instp.pause(true); + + Serial.println("go!"); +} + +void loop() { + CV = digitalRead(22); + count = 0; + + + Insta.update(); + Instb.update(); + Instc.update(); + Instd.update(); + Inste.update(); + Instf.update(); + Instg.update(); + Insth.update(); + Insti.update(); + Instj.update(); + Instk.update(); + Instl.update(); + Instm.update(); + Instn.update(); + Insto.update(); + Instp.update(); + + + + //Messure LDR inputs + VA0 = adsa.readADC_SingleEnded(0); + VA1 = adsa.readADC_SingleEnded(1); + VA2 = adsa.readADC_SingleEnded(2); + VA3 = adsa.readADC_SingleEnded(3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = adsb.readADC_SingleEnded(0); + VA5 = adsb.readADC_SingleEnded(1); + VA6 = adsb.readADC_SingleEnded(2); + VA7 = adsb.readADC_SingleEnded(3); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = adsc.readADC_SingleEnded(0); + VA9 = adsc.readADC_SingleEnded(1); + VA10 = adsc.readADC_SingleEnded(2); + VA11 = adsc.readADC_SingleEnded(3); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.print("VA10: "); Serial.println(VA10); +// Serial.print("VA11: "); Serial.println(VA11); +// Serial.println(" "); + + VA12 = adsd.readADC_SingleEnded(0); + VA13 = adsd.readADC_SingleEnded(1); + VA14 = adsd.readADC_SingleEnded(2); + VA15 = adsd.readADC_SingleEnded(3); + +// Serial.print("VA12: "); Serial.println(VA12); +// Serial.print("VA13: "); Serial.println(VA13); +// Serial.print("VA14: "); Serial.println(VA14); +// Serial.print("VA15: "); Serial.println(VA15); +// Serial.println(" "); + + + + if (VA0 > TH0) { + count++; + ZER = true; + } + else if (VA0 < TH0) { + ZER = false; + } + + if (VA1 > TH1) { + count++; + ONE = true; + } + else if (VA1 < TH1) { + ONE = false; + } + + if (VA2 > TH2) { + count++; + TWO = true; + } + else if (VA2 < TH2) { + TWO = false; + } + + if (VA3 > TH3) { + count++; + THR = true; + } + else if (VA3 < TH3) { + THR = false; + } + + if (VA4 > TH4) { + count++; + FOU = true; + } + else if (VA4 < TH4) { + FOU = false; + } + + if (VA5 > TH5) { + count++; + FIV = true; + } + else if (VA5 < TH5) { + FIV = false; + } + + if (VA6 > TH6) { + count++; + SIX = true; + } + else if (VA6 < TH6) { + SIX = false; + } + + if (VA7 > TH7) { + count++; + SEV = true; + } + else if (VA7 < TH7) { + SEV = false; + } + + if (VA8 > TH8) { + count++; + EIG = true; + } + else if (VA8 < TH8) { + EIG = false; + } + + if (VA9 > TH9) { + count++; + NIN = true; + } + else if (VA9 < TH9) { + NIN = false; + } + + if (VA10 > TH10) { + count++; + TEN = true; + } + else if (VA10 < TH10) { + TEN = false; + } + + if (VA11 > TH11) { + count++; + ELE = true; + } + else if (VA11 < TH11) { + ELE = false; + } + + if (VA12 > TH12) { + count++; + TWE = true; + } + else if (VA12 < TH12) { + TWE = false; + } + + if (VA13 > TH13) { + count++; + THT = true; + } + else if (VA13 < TH13) { + THT = false; + } + + if (VA14 > TH14) { + count++; + FOT = true; + } + else if (VA14 < TH14) { + FOT = false; + } + + if (VA15 > TH15) { + count++; + FIT = true; + } + else if (VA15 < TH15) { + FIT = false; + } + + +// Serial.print("Intruments playing = "); +// Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) + if (ZER) { + VOL0 = 50/count+constrain(map(VA0, TH0, TH0+5000, 0, 65), 0, 65); + Insta.play(true); + Insta.setVolume(VOL0); +// Serial.print("Tone0 active at vol:"); +// Serial.println(VOL0); +// Serial.println(VA0); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(0, HIGH); + } + else if (!CV) { + digitalWrite(0, LOW); + } + } + + if (!ZER) { + Insta.pause (true); + + //Kill ControlVoltage + digitalWrite(0, LOW); + } + + if (ONE) { + VOL1 = 50/count+constrain(map(VA1, TH1, TH1+5000, 0, 65), 0, 65); + Instb.play(true); + Instb.setVolume(VOL1); +// Serial.print("Tone1 active at vol:"); +// Serial.println(VOL1); +// Serial.println(VA1); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(1, HIGH); + } + else if (!CV) { + digitalWrite(1, LOW); + } + } + + if (!ONE) { + Instb.pause (true); + + //Kill ControlVoltage + digitalWrite(1, LOW); + } + + if (TWO) { + VOL2 = 50/count+constrain(map(VA2, TH2, TH2+5000, 0, 65), 0, 65); + Instc.play(true); + Instc.setVolume(VOL2); +// Serial.print("Tone2 active at vol:"); +// Serial.println(VOL2); +// Serial.println(VA2); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(2, HIGH); + } + else if (!CV) { + digitalWrite(2, LOW); + } + } + + if (!TWO) { + Instc.pause (true); + + //Kill ControlVoltage + digitalWrite(2, LOW); + } + + if (THR) { + VOL3 = 50/count+constrain(map(VA3, TH3, TH3+5000, 0, 65), 0, 65); + Instd.play(true); + Instd.setVolume(VOL3); +// Serial.print("Tone3 active at vol:"); +// Serial.println(VOL3); +// Serial.println(VA3); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(3, HIGH); + } + else if (!CV) { + digitalWrite(3, LOW); + } + } + + if (!THR) { + Instd.pause (true); + + //Kill ControlVoltage + digitalWrite(3, LOW); + } + + if (FOU) { + VOL4 = 50/count+constrain(map(VA4, TH4, TH4+5000, 0, 65), 0, 65); + Inste.play(true); + Inste.setVolume(VOL4); +// Serial.print("Tone4 active at vol:"); +// Serial.println(VOL4); +// Serial.println(VA4); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(4, HIGH); + } + else if (!CV) { + digitalWrite(4, LOW); + } + } + + if (!FOU) { + Inste.pause (true); + + //Kill ControlVoltage + digitalWrite(4, LOW); + } + + if (FIV) { + VOL5 = 50/count+constrain(map(VA5, TH5, TH5+5000, 0, 65), 0, 65); + Instf.play(true); + Instf.setVolume(VOL5); +// Serial.print("Tone5 active at vol:"); +// Serial.println(VOL5); +// Serial.println(VA5); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(5, HIGH); + } + else if (!CV) { + digitalWrite(5, LOW); + } + } + + if (!FIV) { + Instf.pause (true); + + //Kill ControlVoltage + digitalWrite(5, LOW); + } + + + if (SIX) { + VOL6 = 50/count+constrain(map(VA6, TH6, TH6+5000, 0, 65), 0, 65); + Instg.play(true); + Instg.setVolume(VOL6); +// Serial.print("Tone6 active at vol:"); +// Serial.println(VOL6); +// Serial.println(VA6); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(6, HIGH); + } + else if (!CV) { + digitalWrite(6, LOW); + } + } + + if (!SIX) { + Instg.pause (true); + + //Kill ControlVoltage + digitalWrite(6, LOW); + } + + if (SEV) { + VOL7 = 50/count+constrain(map(VA7, TH7, TH7+5000, 0, 65), 0, 65); + Insth.play(true); + Insth.setVolume(VOL7); +// Serial.print("Tone7 active at vol:"); +// Serial.println(VOL7); +// Serial.println(VA7); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(7, HIGH); + } + else if (!CV) { + digitalWrite(7, LOW); + } + } + + if (!SEV) { + Insth.pause (true); + + //Kill ControlVoltage + digitalWrite(7, LOW); + } + + + if (EIG) { + VOL8 = 50/count+constrain(map(VA8, TH8, TH8+5000, 0, 65), 0, 65); + Insti.play(true); + Insti.setVolume(VOL8); +// Serial.print("Tone8 active at vol:"); +// Serial.println(VOL8); +// Serial.println(VA8); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(8, HIGH); + } + else if (!CV) { + digitalWrite(8, LOW); + } + } + + if (!EIG) { + Insti.pause (true); + + //Kill ControlVoltage + digitalWrite(8, LOW); + } + + if (NIN) { + VOL9 = 50/count+constrain(map(VA9, TH9, TH9+5000, 0, 65), 0, 65); + Instj.play(true); + Instj.setVolume(VOL9); +// Serial.print("Tone9 active at vol:"); +// Serial.println(VOL9); +// Serial.println(VA9); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(9, HIGH); + } + else if (!CV) { + digitalWrite(9, LOW); + } + } + + if (!NIN) { + Instk.pause (true); + + //Kill ControlVoltage + digitalWrite(9, LOW); + } + + if (TEN) { + VOL10 = 50/count+constrain(map(VA10, TH10, TH10+5000, 0, 65), 0, 65); + Instk.play(true); + Instk.setVolume(VOL10); +// Serial.print("Tone10 active at vol:"); +// Serial.println(VOL10); +// Serial.println(VA10); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(10, HIGH); + } + else if (!CV) { + digitalWrite(10, LOW); + } + } + + if (!TEN) { + Instk.pause (true); + + //Kill ControlVoltage + digitalWrite(10, LOW); + } + + if (ELE) { + VOL11 = 50/count+constrain(map(VA11, TH11, TH11+5000, 0, 65), 0, 65); + Instl.play(true); + Instl.setVolume(VOL11); +// Serial.print("Tone11 active at vol:"); +// Serial.println(VOL11); +// Serial.println(VA11); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(11, HIGH); + } + else if (!CV) { + digitalWrite(11, LOW); + } + } + + if (!ELE) { + Instl.pause (true); + + //Kill ControlVoltage + digitalWrite(11, LOW); + } + + if (TWE) { + VOL12 = 50/count+constrain(map(VA12, TH12, TH12+5000, 0, 65), 0, 65); + Instm.play(true); + Instm.setVolume(VOL12); +// Serial.print("Tone12 active at vol:"); +// Serial.println(VOL12); +// Serial.println(VA12); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(12, HIGH); + } + else if (!CV) { + digitalWrite(12, LOW); + } + } + + if (!TWE) { + Instm.pause (true); + + //Kill ControlVoltage + digitalWrite(12, LOW); + } + + if (THT) { + VOL13 = 50/count+constrain(map(VA13, TH13, TH13+5000, 0, 65), 0, 65); + Instn.play(true); + Instn.setVolume(VOL13); +// Serial.print("Tone13 active at vol:"); +// Serial.println(VOL13); +// Serial.println(VA13); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(13, HIGH); + } + else if (!CV) { + digitalWrite(13, LOW); + } + } + + if (!THT) { + Instn.pause (true); + + //Kill ControlVoltage + digitalWrite(13, LOW); + } + + if (FOT) { + VOL14 = 50/count+constrain(map(VA14, TH14, TH14+5000, 0, 65), 0, 65); + Insto.play(true); + Insto.setVolume(VOL14); +// Serial.print("Tone14 active at vol:"); +// Serial.println(VOL14); +// Serial.println(VA14); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(14, HIGH); + } + else if (!CV) { + digitalWrite(14, LOW); + } + } + + if (!FOT) { + Insto.pause (true); + + //Kill ControlVoltage + digitalWrite(14, LOW); + } + + + if (FIT) { + VOL15 = 50/count+constrain(map(VA15, TH15, TH15+5000, 0, 65), 0, 65); + Instp.play(true); + Instp.setVolume(VOL15); +// Serial.print("Tone15 active at vol:"); +// Serial.println(VOL15); +// Serial.println(VA15); + + //Output ControlVoltage if switch is activated + if (CV) { + digitalWrite(15, HIGH); + } + else if (!CV) { + digitalWrite(15, LOW); + } + } + + if (!FIT) { + Instp.pause (true); + + //Kill ControlVoltage + digitalWrite(15, LOW); + } +} diff --git a/sketches/max_sketch/muziek_zonder_pit_3.1/muziek_zonder_pit_3.1.ino b/sketches/max_sketch/muziek_zonder_pit_3.1/muziek_zonder_pit_3.1.ino new file mode 100644 index 0000000..1529f77 --- /dev/null +++ b/sketches/max_sketch/muziek_zonder_pit_3.1/muziek_zonder_pit_3.1.ino @@ -0,0 +1,680 @@ +#include +//#include +//#include + +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + + +//note values +const char note0[] PROGMEM = ":d=128,b=600,o=3:c+"; //plays c4 +const char note1[] PROGMEM = ":d=128,b=600,o=3:d+"; //plays d4 +const char note2[] PROGMEM = ":d=128,b=600,o=3:e+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=600,o=3:g+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=600,o=3:a+"; //plays a4 +const char note5[] PROGMEM = ":d=128,b=600,o=4:c+"; //plays c5 +const char note6[] PROGMEM = ":d=128,b=600,o=4:d+"; //plays d5 +const char note7[] PROGMEM = ":d=128,b=600,o=4:e+"; //plays e5 +const char note8[] PROGMEM = ":d=128,b=600,o=4:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=600,o=4:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=600,o=5:c+"; //plays c6 +const char note11[] PROGMEM = ":d=128,b=600,o=5:d+"; //plays d6 +const char note12[] PROGMEM = ":d=128,b=600,o=5:e+"; //plays e6 +const char note13[] PROGMEM = ":d=128,b=600,o=5:g+"; //plays g6 +const char note14[] PROGMEM = ":d=128,b=600,o=5:a+"; //plays a6 +const char note15[] PROGMEM = ":d=128,b=600,o=6:c+"; //plays c7 + +MusicWithoutDelay Insta(note0); +MusicWithoutDelay Instb(note1); +MusicWithoutDelay Instc(note2); +MusicWithoutDelay Instd(note3); +MusicWithoutDelay Inste(note4); +MusicWithoutDelay Instf(note5); +MusicWithoutDelay Instg(note6); +MusicWithoutDelay Insth(note7); +MusicWithoutDelay Insti(note8); +MusicWithoutDelay Instj(note9); +MusicWithoutDelay Instk(note10); +MusicWithoutDelay Instl(note11); +MusicWithoutDelay Instm(note12); +MusicWithoutDelay Instn(note13); +MusicWithoutDelay Insto(note14); +MusicWithoutDelay Instp(note15); + + + + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9, VA10, VA11, VA12, VA13, VA14, VA15; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9, TH10, TH11, TH12, TH13, TH14, TH15; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9, VOL10, VOL11, VOL12, VOL13, VOL14, VOL15; +bool CV; + +int ZER; +int ONE; +int TWO; +int THR; +int FOU; +int FIV; +int SIX; +int SEV; +int EIG; +int NIN; +int TEN; +int ELE; +int TWE; +int THT; +int FOT; +int FIT; + +void setup() { + Serial.begin(115200); + pinMode(20, INPUT); + + //set the gain for multiplexed INs + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + Serial.println("Ini MPX "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("MPX Ini"); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + calib(); + + Insta.begin(CHA, TRIANGLE, ENVELOPE0, 0); + Instb.begin(TRIANGLE, ENVELOPE0, 0); + Instc.begin(TRIANGLE, ENVELOPE0, 0); + Instd.begin(TRIANGLE, ENVELOPE0, 0); + Inste.begin(TRIANGLE, ENVELOPE0, 0); + Instf.begin(TRIANGLE, ENVELOPE0, 0); + Instg.begin(TRIANGLE, ENVELOPE0, 0); + Insth.begin(TRIANGLE, ENVELOPE0, 0); + Insti.begin(TRIANGLE, ENVELOPE0, 0); + Instj.begin(TRIANGLE, ENVELOPE0, 0); + Instk.begin(TRIANGLE, ENVELOPE0, 0); + Instl.begin(TRIANGLE, ENVELOPE0, 0); + Instm.begin(TRIANGLE, ENVELOPE0, 0); + Instn.begin(TRIANGLE, ENVELOPE0, 0); + Insto.begin(TRIANGLE, ENVELOPE0, 0); + Instp.begin(TRIANGLE, ENVELOPE0, 0); + + Insta.pause(true); + Instb.pause(true); + Instc.pause(true); + Instd.pause(true); + Inste.pause(true); + Instf.pause(true); + Instg.pause(true); + Insth.pause(true); + Insti.pause(true); + Instj.pause(true); + Instk.pause(true); + Instl.pause(true); + Instm.pause(true); + Instn.pause(true); + Insto.pause(true); + Instp.pause(true); + + Serial.println("go!"); +} + +void calib() { + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (adsa.readADC_SingleEnded(0) + 800); + TH1 = (adsa.readADC_SingleEnded(1) + 800); + TH2 = (adsa.readADC_SingleEnded(2) + 800); + TH3 = (adsa.readADC_SingleEnded(3) + 800); + TH4 = (adsb.readADC_SingleEnded(0) + 800); + TH5 = (adsb.readADC_SingleEnded(1) + 800); + TH6 = (adsb.readADC_SingleEnded(2) + 800); + TH7 = (adsb.readADC_SingleEnded(3) + 800); + TH8 = (adsc.readADC_SingleEnded(0) + 800); + TH9 = (adsc.readADC_SingleEnded(1) + 800); + TH10 = (adsc.readADC_SingleEnded(2) + 800); + TH11 = (adsc.readADC_SingleEnded(3) + 800); + TH12 = (adsd.readADC_SingleEnded(0) + 800); + TH13 = (adsd.readADC_SingleEnded(1) + 800); + TH14 = (adsd.readADC_SingleEnded(2) + 800); + TH15 = (adsd.readADC_SingleEnded(3) + 800); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + Serial.print ("TH10="); + Serial.println (TH10); + Serial.print ("TH11="); + Serial.println (TH11); + Serial.print ("TH12="); + Serial.println (TH12); + Serial.print ("TH13="); + Serial.println (TH13); + Serial.print ("TH14="); + Serial.println (TH14); + Serial.print ("TH15="); + Serial.println (TH15); + } + +void loop() { + bool curcv = digitalRead(20); +// Serial.println (curcv); + count = 0; + + Insta.update(); + Instb.update(); + Instc.update(); + Instd.update(); + Inste.update(); + Instf.update(); + Instg.update(); + Insth.update(); + Insti.update(); + Instj.update(); + Instk.update(); + Instl.update(); + Instm.update(); + Instn.update(); + Insto.update(); + Instp.update(); + + + //Messure LDR inputs + VA0 = adsa.readADC_SingleEnded(0); + VA1 = adsa.readADC_SingleEnded(1); + VA2 = adsa.readADC_SingleEnded(2); + VA3 = adsa.readADC_SingleEnded(3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = adsb.readADC_SingleEnded(0); + VA5 = adsb.readADC_SingleEnded(1); + VA6 = adsb.readADC_SingleEnded(2); + VA7 = adsb.readADC_SingleEnded(3); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = adsc.readADC_SingleEnded(0); + VA9 = adsc.readADC_SingleEnded(1); + VA10 = adsc.readADC_SingleEnded(2); + VA11 = adsc.readADC_SingleEnded(3); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.print("VA10: "); Serial.println(VA10); +// Serial.print("VA11: "); Serial.println(VA11); +// Serial.println(" "); + + VA12 = adsd.readADC_SingleEnded(0); + VA13 = adsd.readADC_SingleEnded(1); + VA14 = adsd.readADC_SingleEnded(2); + VA15 = adsd.readADC_SingleEnded(3); + +// Serial.print("VA12: "); Serial.println(VA12); +// Serial.print("VA13: "); Serial.println(VA13); +// Serial.print("VA14: "); Serial.println(VA14); +// Serial.print("VA15: "); Serial.println(VA15); +// Serial.println(" "); + + if (CV != curcv) { + CV = curcv; + // CV changes +// Serial.print("cv"); +// Serial.println(CV); + if (CV) { + // entering Audio + Serial.println("entering Audio"); + digitalWrite(0, LOW); + digitalWrite(1, LOW); + digitalWrite(2, LOW); + digitalWrite(4, LOW); + digitalWrite(5, LOW); + digitalWrite(6, LOW); + digitalWrite(7, LOW); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + digitalWrite(10, LOW); + digitalWrite(11, LOW); + digitalWrite(12, LOW); + digitalWrite(13, LOW); + digitalWrite(14, LOW); + digitalWrite(15, LOW); + digitalWrite(16, LOW); + } else { + //entering CV + Serial.println("entering CV"); + ZER = false; + ONE = false; + TWO = false; + THR = false; + FOU = false; + FIV = false; + SIX = false; + SEV = false; + EIG = false; + NIN = false; + TEN = false; + ELE = false; + TWE = false; + THT = false; + FOT = false; + FIT = false; + } + } + + if (!CV) { + control(); + } else { + audio(); + } + + //if (digitalRead(17) == LOW) { + //calib(); + //} +} + + void control() { + + if (VA0 > TH0) { + digitalWrite(0, HIGH); + } + else if (VA0 < TH0) { + digitalWrite(0, LOW); + } + + if (VA1 > TH1) { + digitalWrite(1, HIGH); + } + else if (VA1 < TH1) { + digitalWrite(1, LOW); + } + + if (VA2 > TH2) { + digitalWrite(2, HIGH); + } + else if (VA2 < TH2) { + digitalWrite(2, LOW); + } + + if (VA3 > TH3) { + digitalWrite(4, HIGH); + } + else if (VA3 < TH3) { + digitalWrite(4, LOW); + } + + if (VA4 > TH4) { + digitalWrite(5, HIGH); + } + else if (VA4 < TH4) { + digitalWrite(5, LOW); + } + + if (VA5 > TH5) { + digitalWrite(7, HIGH); + } + else if (VA5 < TH5) { + digitalWrite(7, LOW); + } + + if (VA6 > TH6) { + digitalWrite(6, HIGH); + } + else if (VA6 < TH6) { + digitalWrite(6, LOW); + } + + if (VA7 > TH7) { + digitalWrite(8, HIGH); + } + else if (VA7 < TH7) { + digitalWrite(8, LOW); + } + + if (VA8 > TH8) { + digitalWrite(9, HIGH); + } + else if (VA8 < TH8) { + digitalWrite(9, LOW); + } + + if (VA9 > TH9) { + digitalWrite(10, HIGH); + } + else if (VA9 < TH9) { + digitalWrite(10, LOW); + } + + if (VA10 > TH10) { + digitalWrite(12, HIGH); + } + else if (VA10 < TH10) { + digitalWrite(12, LOW); + } + + if (VA11 > TH11) { + digitalWrite(11, HIGH); + } + else if (VA11 < TH11) { + digitalWrite(11, LOW); + } + + if (VA12 > TH12) { + digitalWrite(13, HIGH); + } + else if (VA12 < TH12) { + digitalWrite(13, LOW); + } + + if (VA13 > TH13) { + digitalWrite(14, HIGH); + } + else if (VA13 < TH13) { + digitalWrite(14, LOW); + } + + if (VA14 > TH14) { + digitalWrite(15, HIGH); + } + else if (VA14 < TH14) { + digitalWrite(15, LOW); + } + + if (VA15 > TH15) { + digitalWrite(16, HIGH); + } + else if (VA15 < TH15) { + digitalWrite(16, LOW); + } + } + + + void audio () { + + if (ZER = (VA0 > TH0)) count++; + + if (ONE = (VA1 > TH1)) count++; + + if (TWO = (VA2 > TH2)) count++; + + if (THR = (VA3 > TH3)) count++; + + if (FOU = (VA4 > TH4)) count++; + + if (FIV = (VA5 > TH5)) count++; + + if (SIX = (VA6 > TH6)) count++; + + if (SEV = (VA7 > TH7)) count++; + + if (EIG = (VA8 > TH8)) count++; + + if (NIN = (VA9 > TH9)) count++; + + if (TEN = (VA10 > TH10)) count++; + + if (ELE = (VA11 > TH11)) count++; + + if (TWE = (VA12 > TH12)) count++; + + if (THT = (VA13 > TH13)) count++; + + if (FOT = (VA14 > TH14)) count++; + + if (FIV = (VA15 > TH15)) count++; + + if (ZER) { + VOL0 = 50/count+constrain(map(VA0, TH0, TH0+5000, 0, 65), 0, 65); + Insta.play(true); + Insta.setVolume(VOL0); + // Serial.print("Tone0 active at vol:"); + // Serial.println(VOL0); + // Serial.println(VA0); + } + + if (!ZER) { + Insta.pause (true); + } + + if (ONE) { + VOL1 = 50/count+constrain(map(VA1, TH1, TH1+5000, 0, 65), 0, 65); + Instb.play(true); + Instb.setVolume(VOL1); + // Serial.print("Tone1 active at vol:"); + // Serial.println(VOL1); + // Serial.println(VA1); + } + + if (!ONE) { + Instb.pause (true); + } + + if (TWO) { + VOL2 = 50/count+constrain(map(VA2, TH2, TH2+5000, 0, 65), 0, 65); + Instc.play(true); + Instc.setVolume(VOL2); + // Serial.print("Tone2 active at vol:"); + // Serial.println(VOL2); + // Serial.println(VA2); + } + + if (!TWO) { + Instc.pause (true); + } + + if (THR) { + VOL3 = 50/count+constrain(map(VA3, TH3, TH3+5000, 0, 65), 0, 65); + Instd.play(true); + Instd.setVolume(VOL3); + // Serial.print("Tone3 active at vol:"); + // Serial.println(VOL3); + // Serial.println(VA3); + } + + if (!THR) { + Instd.pause (true); + } + + if (FOU) { + VOL4 = 50/count+constrain(map(VA4, TH4, TH4+5000, 0, 65), 0, 65); + Inste.play(true); + Inste.setVolume(VOL4); + // Serial.print("Tone4 active at vol:"); + // Serial.println(VOL4); + // Serial.println(VA4); + } + + if (!FOU) { + Inste.pause (true); + } + + if (FIV) { + VOL5 = 50/count+constrain(map(VA5, TH5, TH5+5000, 0, 65), 0, 65); + Instf.play(true); + Instf.setVolume(VOL5); + // Serial.print("Tone5 active at vol:"); + // Serial.println(VOL5); + // Serial.println(VA5); + } + + if (!FIV) { + Instf.pause (true); + } + + + if (SIX) { + VOL6 = 50/count+constrain(map(VA6, TH6, TH6+5000, 0, 65), 0, 65); + Instg.play(true); + Instg.setVolume(VOL6); + // Serial.print("Tone6 active at vol:"); + // Serial.println(VOL6); + // Serial.println(VA6); + } + + if (!SIX) { + Instg.pause (true); + } + + if (SEV) { + VOL7 = 50/count+constrain(map(VA7, TH7, TH7+5000, 0, 65), 0, 65); + Insth.play(true); + Insth.setVolume(VOL7); + // Serial.print("Tone7 active at vol:"); + // Serial.println(VOL7); + // Serial.println(VA7); + } + + if (!SEV) { + Insth.pause (true); + } + + + if (EIG) { + VOL8 = 50/count+constrain(map(VA8, TH8, TH8+5000, 0, 65), 0, 65); + Insti.play(true); + Insti.setVolume(VOL8); + // Serial.print("Tone8 active at vol:"); + // Serial.println(VOL8); + // Serial.println(VA8); + } + + if (!EIG) { + Insti.pause (true); + } + + if (NIN) { + VOL9 = 50/count+constrain(map(VA9, TH9, TH9+5000, 0, 65), 0, 65); + Instj.play(true); + Instj.setVolume(VOL9); + // Serial.print("Tone9 active at vol:"); + // Serial.println(VOL9); + // Serial.println(VA9); + } + + if (!NIN) { + Instk.pause (true); + } + + if (TEN) { + VOL10 = 50/count+constrain(map(VA10, TH10, TH10+5000, 0, 65), 0, 65); + Instk.play(true); + Instk.setVolume(VOL10); + // Serial.print("Tone10 active at vol:"); + // Serial.println(VOL10); + // Serial.println(VA10); + } + + if (!TEN) { + Instk.pause (true); + } + + if (ELE) { + VOL11 = 50/count+constrain(map(VA11, TH11, TH11+5000, 0, 65), 0, 65); + Instl.play(true); + Instl.setVolume(VOL11); + // Serial.print("Tone11 active at vol:"); + // Serial.println(VOL11); + // Serial.println(VA11); + } + + if (!ELE) { + Instl.pause (true); + } + + if (TWE) { + VOL12 = 50/count+constrain(map(VA12, TH12, TH12+5000, 0, 65), 0, 65); + Instm.play(true); + Instm.setVolume(VOL12); + // Serial.print("Tone12 active at vol:"); + // Serial.println(VOL12); + // Serial.println(VA12); + + } + + if (!TWE) { + Instm.pause (true); + } + + if (THT) { + VOL13 = 50/count+constrain(map(VA13, TH13, TH13+5000, 0, 65), 0, 65); + Instn.play(true); + Instn.setVolume(VOL13); + // Serial.print("Tone13 active at vol:"); + // Serial.println(VOL13); + // Serial.println(VA13); + } + + if (!THT) { + Instn.pause (true); + } + + if (FOT) { + VOL14 = 50/count+constrain(map(VA14, TH14, TH14+5000, 0, 65), 0, 65); + Insto.play(true); + Insto.setVolume(VOL14); + // Serial.print("Tone14 active at vol:"); + // Serial.println(VOL14); + // Serial.println(VA14); + } + + if (!FOT) { + Insto.pause (true); + } + + + if (FIT) { + VOL15 = 50/count+constrain(map(VA15, TH15, TH15+5000, 0, 65), 0, 65); + Instp.play(true); + Instp.setVolume(VOL15); + // Serial.print("Tone15 active at vol:"); + // Serial.println(VOL15); + // Serial.println(VA15); + } + + if (!FIT) { + Instp.pause (true); + } + Serial.print("Intruments playing = "); + Serial.println(count); + } + + diff --git a/sketches/max_sketch/muziek_zonder_pit_3/muziek_zonder_pit_3.ino b/sketches/max_sketch/muziek_zonder_pit_3/muziek_zonder_pit_3.ino new file mode 100644 index 0000000..7045c1a --- /dev/null +++ b/sketches/max_sketch/muziek_zonder_pit_3/muziek_zonder_pit_3.ino @@ -0,0 +1,767 @@ +#include +//#include +//#include + +#include +#include + +//multiplexer adresses +Adafruit_ADS1115 adsa (0x48); +Adafruit_ADS1115 adsb (0x49); +Adafruit_ADS1115 adsc (0x4A); +Adafruit_ADS1115 adsd (0x4B); + + +//note values +const char note0[] PROGMEM = ":d=128,b=600,o=3:c+"; //plays c4 +const char note1[] PROGMEM = ":d=128,b=600,o=3:d+"; //plays d4 +const char note2[] PROGMEM = ":d=128,b=600,o=3:e+"; //plays e4 +const char note3[] PROGMEM = ":d=128,b=600,o=3:g+"; //plays g4 +const char note4[] PROGMEM = ":d=128,b=600,o=3:a+"; //plays a4 +const char note5[] PROGMEM = ":d=128,b=600,o=4:c+"; //plays c5 +const char note6[] PROGMEM = ":d=128,b=600,o=4:d+"; //plays d5 +const char note7[] PROGMEM = ":d=128,b=600,o=4:e+"; //plays e5 +const char note8[] PROGMEM = ":d=128,b=600,o=4:g+"; //plays g5 +const char note9[] PROGMEM = ":d=128,b=600,o=4:a+"; //plays a5 +const char note10[] PROGMEM = ":d=128,b=600,o=5:c+"; //plays c6 +const char note11[] PROGMEM = ":d=128,b=600,o=5:d+"; //plays d6 +const char note12[] PROGMEM = ":d=128,b=600,o=5:e+"; //plays e6 +const char note13[] PROGMEM = ":d=128,b=600,o=5:g+"; //plays g6 +const char note14[] PROGMEM = ":d=128,b=600,o=5:a+"; //plays a6 +const char note15[] PROGMEM = ":d=128,b=600,o=6:c+"; //plays c7 + +//instruments +MusicWithoutDelay Insta(note0); +MusicWithoutDelay Instb(note1); +MusicWithoutDelay Instc(note2); +MusicWithoutDelay Instd(note3); +MusicWithoutDelay Inste(note4); +MusicWithoutDelay Instf(note5); +MusicWithoutDelay Instg(note6); +MusicWithoutDelay Insth(note7); +MusicWithoutDelay Insti(note8); +MusicWithoutDelay Instj(note9); +MusicWithoutDelay Instk(note10); +MusicWithoutDelay Instl(note11); +MusicWithoutDelay Instm(note12); +MusicWithoutDelay Instn(note13); +MusicWithoutDelay Insto(note14); +MusicWithoutDelay Instp(note15); + + + + +int count; +//int vol; +int VA0, VA1, VA2, VA3, VA4, VA5, VA6, VA7, VA8, VA9, VA10, VA11, VA12, VA13, VA14, VA15; +int TH0, TH1, TH2, TH3, TH4, TH5, TH6, TH7, TH8, TH9, TH10, TH11, TH12, TH13, TH14, TH15; +int VOL0, VOL1, VOL2, VOL3, VOL4, VOL5, VOL6, VOL7, VOL8, VOL9, VOL10, VOL11, VOL12, VOL13, VOL14, VOL15; +bool CV; + +int ZER; +int ONE; +int TWO; +int THR; +int FOU; +int FIV; +int SIX; +int SEV; +int EIG; +int NIN; +int TEN; +int ELE; +int TWE; +int THT; +int FOT; +int FIT; + +void setup() { + Serial.begin(115200); + + //set the gain for multiplexed INs + adsa.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV + adsb.setGain(GAIN_ONE); + adsc.setGain(GAIN_ONE); + adsd.setGain(GAIN_ONE); + + Serial.println("Ini MPX "); + adsa.begin(); + adsb.begin(); + adsc.begin(); + adsd.begin(); + Serial.println("MPX Ini"); + + Serial.println("Wait4MWD"); + Serial.println("Ini MWD"); + + calib(); + + Insta.begin(CHA, TRIANGLE, ENVELOPE0, 0); + Instb.begin(TRIANGLE, ENVELOPE0, 0); + Instc.begin(TRIANGLE, ENVELOPE0, 0); + Instd.begin(TRIANGLE, ENVELOPE0, 0); + Inste.begin(TRIANGLE, ENVELOPE0, 0); + Instf.begin(TRIANGLE, ENVELOPE0, 0); + Instg.begin(TRIANGLE, ENVELOPE0, 0); + Insth.begin(TRIANGLE, ENVELOPE0, 0); + Insti.begin(TRIANGLE, ENVELOPE0, 0); + Instj.begin(TRIANGLE, ENVELOPE0, 0); + Instk.begin(TRIANGLE, ENVELOPE0, 0); + Instl.begin(TRIANGLE, ENVELOPE0, 0); + Instm.begin(TRIANGLE, ENVELOPE0, 0); + Instn.begin(TRIANGLE, ENVELOPE0, 0); + Insto.begin(TRIANGLE, ENVELOPE0, 0); + Instp.begin(TRIANGLE, ENVELOPE0, 0); + + Insta.pause(true); + Instb.pause(true); + Instc.pause(true); + Instd.pause(true); + Inste.pause(true); + Instf.pause(true); + Instg.pause(true); + Insth.pause(true); + Insti.pause(true); + Instj.pause(true); + Instk.pause(true); + Instl.pause(true); + Instm.pause(true); + Instn.pause(true); + Insto.pause(true); + Instp.pause(true); + + Serial.println("go!"); +} + +void calib() { + //calibrate the LDRs + Serial.println ("Calib"); + TH0 = (adsa.readADC_SingleEnded(0) + 800); + TH1 = (adsa.readADC_SingleEnded(1) + 800); + TH2 = (adsa.readADC_SingleEnded(2) + 800); + TH3 = (adsa.readADC_SingleEnded(3) + 800); + TH4 = (adsb.readADC_SingleEnded(0) + 800); + TH5 = (adsb.readADC_SingleEnded(1) + 800); + TH6 = (adsb.readADC_SingleEnded(2) + 800); + TH7 = (adsb.readADC_SingleEnded(3) + 800); + TH8 = (adsc.readADC_SingleEnded(0) + 800); + TH9 = (adsc.readADC_SingleEnded(1) + 800); + TH10 = (adsc.readADC_SingleEnded(2) + 800); + TH11 = (adsc.readADC_SingleEnded(3) + 800); + TH12 = (adsd.readADC_SingleEnded(0) + 800); + TH13 = (adsd.readADC_SingleEnded(1) + 800); + TH14 = (adsd.readADC_SingleEnded(2) + 800); + TH15 = (adsd.readADC_SingleEnded(3) + 800); + + Serial.print ("TH0="); + Serial.println (TH0); + Serial.print ("TH1="); + Serial.println (TH1); + Serial.print ("TH2="); + Serial.println (TH2); + Serial.print ("TH3="); + Serial.println (TH3); + Serial.print ("TH4="); + Serial.println (TH4); + Serial.print ("TH5="); + Serial.println (TH5); + Serial.print ("TH6="); + Serial.println (TH6); + Serial.print ("TH7="); + Serial.println (TH7); + Serial.print ("TH8="); + Serial.println (TH8); + Serial.print ("TH9="); + Serial.println (TH9); + Serial.print ("TH10="); + Serial.println (TH10); + Serial.print ("TH11="); + Serial.println (TH11); + Serial.print ("TH12="); + Serial.println (TH12); + Serial.print ("TH13="); + Serial.println (TH13); + Serial.print ("TH14="); + Serial.println (TH14); + Serial.print ("TH15="); + Serial.println (TH15); + } + +void loop() { + CV = digitalRead(20); + count = 0; + + Insta.update(); + Instb.update(); + Instc.update(); + Instd.update(); + Inste.update(); + Instf.update(); + Instg.update(); + Insth.update(); + Insti.update(); + Instj.update(); + Instk.update(); + Instl.update(); + Instm.update(); + Instn.update(); + Insto.update(); + Instp.update(); + + + //Messure LDR inputs + VA0 = adsa.readADC_SingleEnded(0); + VA1 = adsa.readADC_SingleEnded(1); + VA2 = adsa.readADC_SingleEnded(2); + VA3 = adsa.readADC_SingleEnded(3); + +// Serial.print("VA0: "); Serial.println(VA0); +// Serial.print("VA1: "); Serial.println(VA1); +// Serial.print("VA2: "); Serial.println(VA2); +// Serial.print("VA3: "); Serial.println(VA3); +// Serial.println(" "); + + VA4 = adsb.readADC_SingleEnded(0); + VA5 = adsb.readADC_SingleEnded(1); + VA6 = adsb.readADC_SingleEnded(2); + VA7 = adsb.readADC_SingleEnded(3); + +// Serial.print("VA4: "); Serial.println(VA4); +// Serial.print("VA5: "); Serial.println(VA5); +// Serial.print("VA6: "); Serial.println(VA6); +// Serial.print("VA7: "); Serial.println(VA7); +// Serial.println(" "); + + VA8 = adsc.readADC_SingleEnded(0); + VA9 = adsc.readADC_SingleEnded(1); + VA10 = adsc.readADC_SingleEnded(2); + VA11 = adsc.readADC_SingleEnded(3); + +// Serial.print("VA8: "); Serial.println(VA8); +// Serial.print("VA9: "); Serial.println(VA9); +// Serial.print("VA10: "); Serial.println(VA10); +// Serial.print("VA11: "); Serial.println(VA11); +// Serial.println(" "); + + VA12 = adsd.readADC_SingleEnded(0); + VA13 = adsd.readADC_SingleEnded(1); + VA14 = adsd.readADC_SingleEnded(2); + VA15 = adsd.readADC_SingleEnded(3); + +// Serial.print("VA12: "); Serial.println(VA12); +// Serial.print("VA13: "); Serial.println(VA13); +// Serial.print("VA14: "); Serial.println(VA14); +// Serial.print("VA15: "); Serial.println(VA15); +// Serial.println(" "); + + if (!CV) { + control(); + } + + if (CV) { + audio(); + } + + if (digitalRead(17) == LOW) { + calib(); + } +} + + void control() { + ZER = false; + ONE = false; + TWO = false; + THR = false; + FOU = false; + FIV = false; + SIX = false; + SEV = false; + EIG = false; + NIN = false; + TEN = false; + ELE = false; + TWE = false; + THT = false; + FOT = false; + FIT = false; + + if (VA0 > TH0) { + digitalWrite(0, HIGH); + } + else if (VA0 < TH0) { + digitalWrite(0, LOW); + } + + if (VA1 > TH1) { + digitalWrite(1, HIGH); + } + else if (VA1 < TH1) { + digitalWrite(1, LOW); + } + + if (VA2 > TH2) { + digitalWrite(2, HIGH); + } + else if (VA2 < TH2) { + digitalWrite(2, LOW); + } + + if (VA3 > TH3) { + digitalWrite(4, HIGH); + } + else if (VA3 < TH3) { + digitalWrite(4, LOW); + } + + if (VA4 > TH4) { + digitalWrite(5, HIGH); + } + else if (VA4 < TH4) { + digitalWrite(5, LOW); + } + + if (VA5 > TH5) { + digitalWrite(7, HIGH); + } + else if (VA5 < TH5) { + digitalWrite(7, LOW); + } + + if (VA6 > TH6) { + digitalWrite(6, HIGH); + } + else if (VA6 < TH6) { + digitalWrite(6, LOW); + } + + if (VA7 > TH7) { + digitalWrite(8, HIGH); + } + else if (VA7 < TH7) { + digitalWrite(8, LOW); + } + + if (VA8 > TH8) { + digitalWrite(9, HIGH); + } + else if (VA8 < TH8) { + digitalWrite(9, LOW); + } + + if (VA9 > TH9) { + digitalWrite(10, HIGH); + } + else if (VA9 < TH9) { + digitalWrite(10, LOW); + } + + if (VA10 > TH10) { + digitalWrite(12, HIGH); + } + else if (VA10 < TH10) { + digitalWrite(12, LOW); + } + + if (VA11 > TH11) { + digitalWrite(11, HIGH); + } + else if (VA11 < TH11) { + digitalWrite(11, LOW); + } + + if (VA12 > TH12) { + digitalWrite(13, HIGH); + } + else if (VA12 < TH12) { + digitalWrite(13, LOW); + } + + if (VA13 > TH13) { + digitalWrite(14, HIGH); + } + else if (VA13 < TH13) { + digitalWrite(14, LOW); + } + + if (VA14 > TH14) { + digitalWrite(15, HIGH); + } + else if (VA14 < TH14) { + digitalWrite(15, LOW); + } + + if (VA15 > TH15) { + digitalWrite(16, HIGH); + } + else if (VA15 < TH15) { + digitalWrite(16, LOW); + } + } + + + void audio () { + + digitalWrite(0, LOW); + digitalWrite(1, LOW); + digitalWrite(2, LOW); + digitalWrite(4, LOW); + digitalWrite(5, LOW); + digitalWrite(6, LOW); + digitalWrite(7, LOW); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + digitalWrite(10, LOW); + digitalWrite(11, LOW); + digitalWrite(12, LOW); + digitalWrite(13, LOW); + digitalWrite(14, LOW); + digitalWrite(15, LOW); + digitalWrite(16, LOW); + + if (VA0 > TH0) { + count++; + ZER = true; + } + else if (VA0 < TH0) { + ZER = false; + } + + if (VA1 > TH1) { + count++; + ONE = true; + } + else if (VA1 < TH1) { + ONE = false; + } + + if (VA2 > TH2) { + count++; + TWO = true; + } + else if (VA2 < TH2) { + TWO = false; + } + + if (VA3 > TH3) { + count++; + THR = true; + } + else if (VA3 < TH3) { + THR = false; + } + + if (VA4 > TH4) { + count++; + FOU = true; + } + else if (VA4 < TH4) { + FOU = false; + } + + if (VA5 > TH5) { + count++; + FIV = true; + } + else if (VA5 < TH5) { + FIV = false; + } + + if (VA6 > TH6) { + count++; + SIX = true; + } + else if (VA6 < TH6) { + SIX = false; + } + + if (VA7 > TH7) { + count++; + SEV = true; + } + else if (VA7 < TH7) { + SEV = false; + } + + if (VA8 > TH8) { + count++; + EIG = true; + } + else if (VA8 < TH8) { + EIG = false; + } + + if (VA9 > TH9) { + count++; + NIN = true; + } + else if (VA9 < TH9) { + NIN = false; + } + + if (VA10 > TH10) { + count++; + TEN = true; + } + else if (VA10 < TH10) { + TEN = false; + } + + if (VA11 > TH11) { + count++; + ELE = true; + } + else if (VA11 < TH11) { + ELE = false; + } + + if (VA12 > TH12) { + count++; + TWE = true; + } + else if (VA12 < TH12) { + TWE = false; + } + + if (VA13 > TH13) { + count++; + THT = true; + } + else if (VA13 < TH13) { + THT = false; + } + + if (VA14 > TH14) { + count++; + FOT = true; + } + else if (VA14 < TH14) { + FOT = false; + } + + if (VA15 > TH15) { + count++; + FIV = true; + } + else if (VA15 < TH15) { + FIV = false; + } + + if (ZER) { + VOL0 = 50/count+constrain(map(VA0, TH0, TH0+5000, 0, 65), 0, 65); + Insta.play(true); + Insta.setVolume(VOL0); +// Serial.print("Tone0 active at vol:"); +// Serial.println(VOL0); +// Serial.println(VA0); + } + + if (!ZER) { + Insta.pause (true); + } + + if (ONE) { + VOL1 = 50/count+constrain(map(VA1, TH1, TH1+5000, 0, 65), 0, 65); + Instb.play(true); + Instb.setVolume(VOL1); +// Serial.print("Tone1 active at vol:"); +// Serial.println(VOL1); +// Serial.println(VA1); + } + + if (!ONE) { + Instb.pause (true); + } + + if (TWO) { + VOL2 = 50/count+constrain(map(VA2, TH2, TH2+5000, 0, 65), 0, 65); + Instc.play(true); + Instc.setVolume(VOL2); +// Serial.print("Tone2 active at vol:"); +// Serial.println(VOL2); +// Serial.println(VA2); + } + + if (!TWO) { + Instc.pause (true); + } + + if (THR) { + VOL3 = 50/count+constrain(map(VA3, TH3, TH3+5000, 0, 65), 0, 65); + Instd.play(true); + Instd.setVolume(VOL3); +// Serial.print("Tone3 active at vol:"); +// Serial.println(VOL3); +// Serial.println(VA3); + } + + if (!THR) { + Instd.pause (true); + } + + if (FOU) { + VOL4 = 50/count+constrain(map(VA4, TH4, TH4+5000, 0, 65), 0, 65); + Inste.play(true); + Inste.setVolume(VOL4); +// Serial.print("Tone4 active at vol:"); +// Serial.println(VOL4); +// Serial.println(VA4); + } + + if (!FOU) { + Inste.pause (true); + } + + if (FIV) { + VOL5 = 50/count+constrain(map(VA5, TH5, TH5+5000, 0, 65), 0, 65); + Instf.play(true); + Instf.setVolume(VOL5); +// Serial.print("Tone5 active at vol:"); +// Serial.println(VOL5); +// Serial.println(VA5); + } + + if (!FIV) { + Instf.pause (true); + } + + + if (SIX) { + VOL6 = 50/count+constrain(map(VA6, TH6, TH6+5000, 0, 65), 0, 65); + Instg.play(true); + Instg.setVolume(VOL6); +// Serial.print("Tone6 active at vol:"); +// Serial.println(VOL6); +// Serial.println(VA6); + } + + if (!SIX) { + Instg.pause (true); + } + + if (SEV) { + VOL7 = 50/count+constrain(map(VA7, TH7, TH7+5000, 0, 65), 0, 65); + Insth.play(true); + Insth.setVolume(VOL7); +// Serial.print("Tone7 active at vol:"); +// Serial.println(VOL7); +// Serial.println(VA7); + } + + if (!SEV) { + Insth.pause (true); + } + + + if (EIG) { + VOL8 = 50/count+constrain(map(VA8, TH8, TH8+5000, 0, 65), 0, 65); + Insti.play(true); + Insti.setVolume(VOL8); +// Serial.print("Tone8 active at vol:"); +// Serial.println(VOL8); +// Serial.println(VA8); + } + + if (!EIG) { + Insti.pause (true); + } + + if (NIN) { + VOL9 = 50/count+constrain(map(VA9, TH9, TH9+5000, 0, 65), 0, 65); + Instj.play(true); + Instj.setVolume(VOL9); +// Serial.print("Tone9 active at vol:"); +// Serial.println(VOL9); +// Serial.println(VA9); + } + + if (!NIN) { + Instk.pause (true); + } + + if (TEN) { + VOL10 = 50/count+constrain(map(VA10, TH10, TH10+5000, 0, 65), 0, 65); + Instk.play(true); + Instk.setVolume(VOL10); +// Serial.print("Tone10 active at vol:"); +// Serial.println(VOL10); +// Serial.println(VA10); + } + + if (!TEN) { + Instk.pause (true); + } + + if (ELE) { + VOL11 = 50/count+constrain(map(VA11, TH11, TH11+5000, 0, 65), 0, 65); + Instl.play(true); + Instl.setVolume(VOL11); +// Serial.print("Tone11 active at vol:"); +// Serial.println(VOL11); +// Serial.println(VA11); + } + + if (!ELE) { + Instl.pause (true); + } + + if (TWE) { + VOL12 = 50/count+constrain(map(VA12, TH12, TH12+5000, 0, 65), 0, 65); + Instm.play(true); + Instm.setVolume(VOL12); +// Serial.print("Tone12 active at vol:"); +// Serial.println(VOL12); +// Serial.println(VA12); + + } + + if (!TWE) { + Instm.pause (true); + } + + if (THT) { + VOL13 = 50/count+constrain(map(VA13, TH13, TH13+5000, 0, 65), 0, 65); + Instn.play(true); + Instn.setVolume(VOL13); +// Serial.print("Tone13 active at vol:"); +// Serial.println(VOL13); +// Serial.println(VA13); + } + + if (!THT) { + Instn.pause (true); + } + + if (FOT) { + VOL14 = 50/count+constrain(map(VA14, TH14, TH14+5000, 0, 65), 0, 65); + Insto.play(true); + Insto.setVolume(VOL14); +// Serial.print("Tone14 active at vol:"); +// Serial.println(VOL14); +// Serial.println(VA14); + } + + if (!FOT) { + Insto.pause (true); + } + + + if (FIT) { + VOL15 = 50/count+constrain(map(VA15, TH15, TH15+5000, 0, 65), 0, 65); + Instp.play(true); + Instp.setVolume(VOL15); +// Serial.print("Tone15 active at vol:"); +// Serial.println(VOL15); +// Serial.println(VA15); + } + + if (!FIT) { + Instp.pause (true); + } + + } + +// Serial.print("Intruments playing = "); +// Serial.println(count); + + //Play notes and mix down (set volume depending on number of notes playing) +