You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
332 lines
8.5 KiB
C++
332 lines
8.5 KiB
C++
#include <MusicWithoutDelay.h>
|
|
//#include <synth.h>
|
|
//#include <tables.h>
|
|
|
|
// #include <Wire.h>
|
|
#include <Adafruit_ADS1015.h>
|
|
|
|
//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");
|
|
// }
|
|
}
|