#include #include #include Adafruit_ADS1115 adsa (0x48); Adafruit_ADS1115 adsb (0x49); Adafruit_ADS1115 adsc (0x4A); Adafruit_ADS1115 adsd (0x4B); const char note0[] PROGMEM = ":d=128,b=600,o=3:c+"; const char note1[] PROGMEM = ":d=128,b=600,o=3:d+"; const char note2[] PROGMEM = ":d=128,b=600,o=3:e+"; const char note3[] PROGMEM = ":d=128,b=600,o=3:g+"; const char note4[] PROGMEM = ":d=128,b=600,o=3:a+"; const char note5[] PROGMEM = ":d=128,b=600,o=4:c+"; const char note6[] PROGMEM = ":d=128,b=600,o=4:d+"; const char note7[] PROGMEM = ":d=128,b=600,o=4:e+"; const char note8[] PROGMEM = ":d=128,b=600,o=4:g+"; const char note9[] PROGMEM = ":d=128,b=600,o=4:a+"; const char note10[] PROGMEM = ":d=128,b=600,o=5:c+"; const char note11[] PROGMEM = ":d=128,b=600,o=5:d+"; const char note12[] PROGMEM = ":d=128,b=600,o=5:e+"; const char note13[] PROGMEM = ":d=128,b=600,o=5:g+"; const char note14[] PROGMEM = ":d=128,b=600,o=5:a+"; const char note15[] PROGMEM = ":d=128,b=600,o=6:c+"; 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 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() { pinMode(20, INPUT); pinMode(17, INPUT); pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); pinMode(14, OUTPUT); pinMode(15, OUTPUT); pinMode(16, OUTPUT); adsa.setGain(GAIN_ONE); adsb.setGain(GAIN_ONE); adsc.setGain(GAIN_ONE); adsd.setGain(GAIN_ONE); adsa.begin(); adsb.begin(); adsc.begin(); adsd.begin(); 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); } void 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); } void loop() { bool curcv = digitalRead(17); 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(); VA0 = adsa.readADC_SingleEnded(0); VA1 = adsa.readADC_SingleEnded(1); VA2 = adsa.readADC_SingleEnded(2); VA3 = adsa.readADC_SingleEnded(3); VA4 = adsb.readADC_SingleEnded(0); VA5 = adsb.readADC_SingleEnded(1); VA6 = adsb.readADC_SingleEnded(2); VA7 = adsb.readADC_SingleEnded(3); VA8 = adsc.readADC_SingleEnded(0); VA9 = adsc.readADC_SingleEnded(1); VA10 = adsc.readADC_SingleEnded(2); VA11 = adsc.readADC_SingleEnded(3); VA12 = adsd.readADC_SingleEnded(0); VA13 = adsd.readADC_SingleEnded(1); VA14 = adsd.readADC_SingleEnded(2); VA15 = adsd.readADC_SingleEnded(3); if (CV != curcv) { CV = curcv; if (CV) { 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 { 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(20) == LOW) { calib(); } } void control() { if (VA0 > TH0) { digitalWrite(0, HIGH); } else{ digitalWrite(0, LOW); } if (VA1 > TH1) { digitalWrite(1, HIGH); } else{ digitalWrite(1, LOW); } if (VA2 > TH2) { digitalWrite(2, HIGH); } else { digitalWrite(2, LOW); } if (VA3 > TH3) { digitalWrite(4, HIGH); } else { digitalWrite(4, LOW); } if (VA4 > TH4) { digitalWrite(5, HIGH); } else { digitalWrite(5, LOW); } if (VA5 > TH5) { digitalWrite(7, HIGH); } else { digitalWrite(7, LOW); } if (VA6 > TH6) { digitalWrite(6, HIGH); } else { digitalWrite(6, LOW); } if (VA7 > TH7) { digitalWrite(8, HIGH); } else { digitalWrite(8, LOW); } if (VA8 > TH8) { digitalWrite(9, HIGH); } else { digitalWrite(9, LOW); } if (VA9 > TH9) { digitalWrite(10, HIGH); } else { digitalWrite(10, LOW); } if (VA10 > TH10) { digitalWrite(12, HIGH); } else { digitalWrite(12, LOW); } if (VA11 > TH11) { digitalWrite(11, HIGH); } else { digitalWrite(11, LOW); } if (VA12 > TH12) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } if (VA13 > TH13) { digitalWrite(14, HIGH); } else { digitalWrite(14, LOW); } if (VA14 > TH14) { digitalWrite(15, HIGH); } else { digitalWrite(15, LOW); } if (VA15 > TH15) { digitalWrite(16, HIGH); } else { 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 (FIT = (VA15 > TH15)) count++; if (ZER) { VOL0 = 50/count+constrain(map(VA0, TH0, TH0+5000, 0, 65), 0, 65); Insta.play(true); Insta.setVolume(VOL0); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } if (!FIT) { Instp.pause (true); } }