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.

572 lines
12 KiB
C++

#include <SensorToButton.h>
#include <MusicWithoutDelay.h>
#include <synth.h>
#include <tables.h>
//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);
}
}