
//Soft serial library used to send serial commands on pin 2 instead of regular serial pin.
#include <SoftwareSerial.h>

#define RES  3
#define txPin  2
#define buttonPositionTwo 13 //position 2 on button (IN)
#define buttonPositionOne 12 //position 1 on button (DOWN)
#define buttonPositionThree 11 //position T on button (UP)
#define shutDownAmp 4
#define red 7
#define green 6 
#define blue 5

long tone1;
long tone2;
long tone3;
long tone4;
long tone5;
long tone6;
long tone7;
long tone8;
long tone9;
long tone10;
long tone11;
long tone12;

//Create a SoftSerial Objet
SoftwareSerial speakjet = SoftwareSerial(0, txPin);

void setup()  
{

  pinMode(txPin, OUTPUT);
  pinMode(buttonPositionOne, INPUT);
  pinMode(buttonPositionTwo, INPUT);
  pinMode(buttonPositionThree, INPUT);
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(shutDownAmp, OUTPUT); 
  pinMode(green, OUTPUT); 

  //Set up a serial port to talk from Arduino to the SpeakJet
  speakjet.begin(9600);    

  digitalWrite(shutDownAmp, LOW); //or you'll hear 'ready' from the speakjet at power up

  //Configure Reset line as an output
  pinMode(RES, OUTPUT);

  //All I/O pins are configured. Reset the SpeakJet module
  digitalWrite(RES, LOW);
  delay(100);
  digitalWrite(RES, HIGH);
  
  //set RGB LED off
  digitalWrite(red, LOW);
  digitalWrite(blue, LOW);
  digitalWrite(green,LOW);
}

void loop()
{  
  //set to known good state
  digitalWrite(shutDownAmp, LOW); //shut down amp 
  digitalWrite(blue, LOW);
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);

  if (digitalRead(buttonPositionTwo) == LOW) { //IN

    //turn the amp on
    digitalWrite(shutDownAmp, HIGH); //turn amp on

    tone1 = random(200,240); //pick random tone from range;
    tone2 = random(200,240); //pick random tone from range;
    tone3 = random(200,240); //pick random tone from range;
    tone4 = random(200,240); //pick random tone from range;
    tone5 = random(200,240); //pick random tone from range;
    tone6 = random(200,240); //pick random tone from range;
    tone7 = random(200,240); //pick random tone from range;
    tone8 = random(200,240); //pick random tone from range;
    tone9 = random(200,240); //pick random tone from range;
    tone10 = random(200,240); //pick random tone from range;
    tone11 = random(200,240); //pick random tone from range;
    tone12 = random(200,240); //pick random tone from range;

    //235,238,239
    //skip 211, 212, 213, 214, 226, 230, 231, 232, 233, 234, 236, 237

    if (((tone1 > 210) && (tone1 < 215)) || (tone1 = 226) || ((tone1 > 229) && (tone1 < 235)) || ((tone1 > 234) && (tone1 < 238))) {      
      tone1 = random(219,227); 
    }
    if (((tone2 > 210) && (tone2 < 215)) || (tone2 = 226) || ((tone2 > 229) && (tone2 < 235)) || ((tone2 > 234) && (tone2 < 238))) {
      tone2 = random(219,227); 
    }
    if (((tone3 > 210) && (tone3 < 215)) || (tone3 = 226) || ((tone3 > 229) && (tone3 < 235)) || ((tone3 > 234) && (tone3 < 238))) {
      tone3 = random(219,227); 
    }
    if (((tone4 > 210) && (tone4 < 215)) || (tone4 = 226) || ((tone4 > 229) && (tone4 < 235)) || ((tone4 > 234) && (tone4 < 238))) {
      tone4 = random(219,227); 
    }
    if (((tone5 > 210) && (tone5 < 215)) || (tone5 = 226) || ((tone5 > 229) && (tone5 < 235)) || ((tone5 > 234) && (tone5 < 238))) {
      tone5 = random(219,227); 
    }
    if (((tone6 > 210) && (tone6 < 215)) || (tone6 = 226) || ((tone6 > 229) && (tone6 < 235)) || ((tone6 > 234) && (tone6 < 238))) {
      tone6 = random(219,227); 
    }
    if (((tone7 > 210) && (tone7 < 215)) || (tone7 = 226) || ((tone7 > 229) && (tone7 < 235)) || ((tone7 > 234) && (tone7 < 238))) {
      tone7 = random(219,227); 
    }  
    if (((tone8 > 210) && (tone8 < 215)) || (tone8 = 226) || ((tone8 > 229) && (tone8 < 235)) || ((tone8 > 234) && (tone8 < 238))) {
      tone8 = random(219,227); 
    } 
    if (((tone9 > 210) && (tone9 < 215)) || (tone9 = 226) || ((tone9 > 229) && (tone9 < 235)) || ((tone9 > 234) && (tone9 < 238))) {
      tone9 = random(219,227); 
    } 
    if (((tone10 > 210) && (tone10 < 215)) || (tone10 = 226) || ((tone10 > 229) && (tone10 < 235)) || ((tone10 > 234) && (tone10 < 238))) {
      tone10 = random(219,227); 
    }   
    if (((tone11 > 210) && (tone12 < 215)) || (tone11 = 226) || ((tone11 > 229) && (tone11 < 235)) || ((tone11 > 234) && (tone11 < 238))) {
      tone11 = random(222,224); 
    }
    if (((tone12 > 210) && (tone12 < 215)) || (tone12 = 226) || ((tone12 > 229) && (tone12 < 235)) || ((tone12 > 234) && (tone12 < 238))) {
      tone12 = random(220,226); 
    }

    /*
     000 Pause 0
     001 Pause 1
     002 Pause 2
     003 Pause 3
     004 Pause 4
     005 Pause 5
     006 Pause 6
     007 Play Next Sound Fast
     008 Play Next Sound Slow
     014 Play Next Sound High Tone
     015 Play Next Sound Low Tone
     016 Wait
     020 Volume, X   //default 96
     021 Speed, X    //default 114
     022 Pitch, X   //default 88
     023 Bend, X   /default 5
     024 PortCtr, X    //default  7
     025 Port, X
     026 Repeat, X
     028 Call Phrase, X
     029 Goto Phrase, X
     030 Delay, X
     031 Reset Defaults
     */

    //Start Enunciating
    speakjet.print("\\0"); //enter SCP mode
    speakjet.print("R"); //clear buffer
    speakjet.print("X"); //exit SC mode

    char message1[] = {
      20, 96, 21, 114, 22, 88, tone1,tone2, 4,tone3,tone4, 4,tone5,tone6,tone7,tone8, 4, tone9,tone10,tone11, 4,tone12,255,16                    };
    
    speakjet.print(message1);

    //flash LED in blue and red
    digitalWrite(red, HIGH);
    delay(500);
    digitalWrite(red, LOW);
    digitalWrite(blue, HIGH);
    delay(500);
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
    delay(500);
    digitalWrite(red, LOW);
    digitalWrite(blue, HIGH);
    delay(500);
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
    delay(500);
    digitalWrite(red, LOW);

    //delay(3000); 

  } 

  if (digitalRead(buttonPositionOne) == LOW) { //DOWN

   digitalWrite(green, HIGH);

  //speakjet.print("\\0");
  digitalWrite(shutDownAmp, HIGH); //turn amp on

  //Start Enunciating
  speakjet.print("\\0"); //enter SCP mode
  speakjet.print("R"); //clear buffer
  speakjet.print("X"); //exit SC mode

  char message2[] = {
    20, 96, 21, 114, 22, 88, 23, 5, 8, 135, 8, 146, 5, 128, 153, 5, 170, 154, 8, 188, 5, 152, 5, 170, 8,128,146,8,135,8,144,5,8,191,162,5,8,134,187,255,16  };
  speakjet.print(message2);
  delay(3000);

  digitalWrite(green, LOW);
  }


  if (digitalRead(buttonPositionThree) == LOW) { //UP

    digitalWrite(red, HIGH);
    delay(1000);
    digitalWrite(red, LOW);
  }

}









