byte commandLength;
byte command[19];
byte sndCmd[4];
int DataFldr = 33;//7 Segment Folder Display
int LatchFldr = 34;//7 Segment Folder Display
int ClockFldr = 35;//7 Segment Folder Display
int DataTrk = 36;//7 Segment Track Display
int LatchTrk = 37;//7 Segment Track Display
int ClockTrk = 38;//7 Segment Track Display
int DataSpkr = 39;//Spkr Relays
int LatchSpkr = 40;//Spkr Relays
int ClockSpkr = 41;//Spkr Relays
int DataLgt = 42;//Light Transistors & Relays
int LatchLgt = 43;//Light Transistors & Relays
int ClockLgt = 44;//Light Transistors & Relays
int fldrDigit1;
int fldrDigit2;
int trkDigit1;
int trkDigit2;
int busyPin1 = 49;//receives busy signal from DY-SV5W board 1
int busyLed1 = 48;
int busyPinState1;
int busyPin2 = 51;//receives busy signal from DY-SV5W board 2
int busyLed2 = 50;
int busyPinState2;
int busyPin3 = 53;//receives busy signal from DY-SV5W board 3
int busyLed3 = 52;
int busyPinState3;
int lgtAll = 45;//***********************************************************************************************************************************************************************************************
int lgtState;
int dblSound = 46;//***********************************************************************************************************************************************************************************************
int dblState;
int pinBtn [23] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};//Arduino Pin #s for buttons
int valNum [23] = {"V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", "V12", "V13", "V14", "V15", "V16", "V17", "V18", "V19", "V20", "V21", "V22", "V23"};//Container for Pin status (HIGH or LOW)
int checkSum;
int sndFldr;
int randNumb1;
int Vol = 22;//Initial Volume setting from 1 - 30
int disp [11][8] = {
{1,1,1,1,1,1,0,0},//0 - Write 7 segment positions A, B, C, D, E, F = HIGH(1) and positions G = LOW(0) and DP Pin not used for project
{0,1,1,0,0,0,0,0},//1
{1,1,0,1,1,0,1,0},//2
{1,1,1,1,0,0,1,0},//3
{0,1,1,0,0,1,1,0},//4
{1,0,1,1,0,1,1,0},//5
{1,0,1,1,1,1,1,0},//6
{1,1,1,0,0,0,0,0},//7
{1,1,1,1,1,1,1,0},//8
{1,1,1,1,0,1,1,0},//9
{0,0,0,0,0,0,0,0}//Blank - No segments illuminated
};
int spkrNumGrpA [17][16] = {
{1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1},//Write spkr realay 1 = LOW(0: ON) and all other relays = HIGH(1: OFF)
{1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1},//2
{1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1},//3
{1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1},//4
{1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1},//5
{1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1},//6
{1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},//7
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},//8
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},//9
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},//10
{1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1},//11
{1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1},//12
{1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},//13
{1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1},//14
{1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1},//15
{1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1},//16
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}//Blank - No spkr relays on
};
int spkrNumGrpB [17][16] = {
{1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1},//Write spkr realay 1 = LOW(0: ON) and all other relays = HIGH(1: OFF)
{1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1},//2
{1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1},//3
{1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1},//4
{1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1},//5
{1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1},//6
{1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},//7
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},//8
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},//9
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},//10
{1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1},//11
{1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1},//12
{1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},//13
{1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1},//14
{1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1},//15
{1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1},//16
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}//Blank - No spkr relays on
};
//0 = Grinch Lair
//1 = Cabin
//2 = Cabin Smoke
//3 = Campfire
//4 = Campfire Smoke
//5 = Gazebo
//6 = House #4
//7 = Home Alone House
//8 = House #2
//9 = Church
//10 = Bell Tower
//11 = Train Station
//12 = Polar Express House
//13 = Hotel
//14 = Restaurant
//15 = Pub
//16 = Toy Store
//17 = Pet Shop
//18 = Theater
//19 = Flower Shop
//20 = School
//21 = Town Hall
//22 = Fire Station
//23 = Clock Store
//24 = Bank
//25 = Bakery
//26 = Antique Store
//27 = Coffee Shop
//28 = Gift Store
//29 = Christmas Tree
//30 = Lamp Post Set - Gift Store
//31 = Lamp Post Set - Antique Store
//32 = Lamp Post Set - Bank
//33 = Lamp Post Set - Fire Station
//34 = Lamp Post Set - Train Station
//35 = Lamp Post Set - School
//36 = Lamp Post Set - Theater
//37 = Lamp Post Set - Toy Store
//38 = Lamp Post Set - Restaurant
//39 = North Pole Village Bldg1
//40 = North Pole Village Bldg2
//41 = North Pole Village Bldg3
//42 = North Pole Village Bldg4
//43 = North Pole Village Bldg5
//44 = Santa Sleigh
//45 = Ice Skaters
int lgtNum [19][48] = {
//{0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5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0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0}//18: Elf & Santa
};
// 3rd Board - ability to play 2 sounds at once
// Rec sequence and Playback - 2 memory positions
// Sleep mode if no input for x amount of time
void sendCommand(int z){
if (z == 5){
for(int i=0; i<commandLength; i++){
Serial1.write(command[i]);//Write to 2nd DY-SV5W Board
}
} else {
for(int i=0; i<commandLength; i++){
Serial2.write(command[i]);//Write to 1st DY-SV5W Board
}
}
}
void Stop(){//Stop playing track
command[0] = 0xAA;// = 170
command[1] = 0x04;// = 4 in decimal
command[2] = 0x00;// = 0
command[3] = 0xAE;// = 174
commandLength = 4;
sendCommand(1);
sendCommand(5);
}
void upVol(){//Adjust Volume Up
command[0] = 0xAA;// = 170
command[1] = 0x14;// = 20 in decimal
command[2] = 0x00;// = 0
command[3] = 0xBE;// = 190
commandLength = 4;
sendCommand(1);
sendCommand(5);
}
void dwnVol(){//Adjust Volume Down
command[0] = 0xAA;// = 170
command[1] = 0x15;// = 21 in decimal
command[2] = 0x00;// = 0
command[3] = 0xBF;// = 191
commandLength = 4;
sendCommand(1);
sendCommand(5);
}
void setVol(){
command[0] = 170;//= 0xAA in Hex
command[1] = 0x13;//= 19 in decimal
command[2] = 1;
command[3] = Vol;
command[4] = (command[0] + command[1] + command[2] + command[3]);
commandLength = 5;
sendCommand(1);
sendCommand(5);
}
void clrLght(){
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[0][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
}
void lgtSw(int q){
clrLght();
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[q][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
}
void Campfire(){
clrLght();
for (int j=0; j<50; j++){
randNumb1 = (rand() % 10);
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[12][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
delay(randNumb1*150);
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[13][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
}
}
void Cabin(){
clrLght();
for (int j=0; j<50; j++){
randNumb1 = (rand() % 10);
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[15][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
delay(randNumb1*150);
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[16][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
}
}
void lgtBlnk(){
clrLght();
for (int j=0; j<50; j++){
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[10][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
delay(500);
for (int i=0; i<48; i++){
digitalWrite(DataLgt, lgtNum[11][i]);
digitalWrite(ClockLgt, HIGH);
digitalWrite(ClockLgt, LOW);
}
digitalWrite(LatchLgt, HIGH);
digitalWrite(LatchLgt, LOW);
}
}
void clrTrk(){
for (int i=0; i<2; i++){//Set both Track digits blank
for (int j=0; j<8; j++){
digitalWrite(DataTrk, disp[10][j]);
digitalWrite(ClockTrk, HIGH);
digitalWrite(ClockTrk, LOW);
}
}
digitalWrite(LatchTrk, HIGH);
digitalWrite(LatchTrk, LOW);
}
void trkPlay(int fldrNum, int trkNum, int lgtCond){
clrTrk();
if (trkNum == 20){
command[11] = 0x30;// 0
command[12] = 0x32;// 2
command[13] = 28+trkNum;//0 = 0x30 = 48 to 9 = 0x39 = 57
}else if (trkNum < 10){
command[11] = 0x30;// 0
command[12] = 0x30;// 0
command[13] = 48+trkNum;//1 = 0x31 = 49 to 9 = 0x39 = 57
}else{
command[11] = 0x30;// 0
command[12] = 0x31;// 1
command[13] = 38+trkNum;//0 = 0x30 = 48 to 9 = 0x39 = 57
}
int tmp2 = trkNum;
trkDigit2 = trkNum%10;//2nd digit of "trkNum"
trkDigit1 = trkNum /= 10;//1st digit of "trkNum"
if (tmp2<10){
for (int i=0; i<8; i++){
digitalWrite(DataTrk, disp[tmp2][i]);//Turn on selected 7 segments for 2nd digit
digitalWrite(ClockTrk, HIGH);
digitalWrite(ClockTrk, LOW);
}
for (int i=0; i<8; i++){
digitalWrite(DataTrk, disp[10][i]);//Turn all 7 segments off for 1st digit
digitalWrite(ClockTrk, HIGH);
digitalWrite(ClockTrk, LOW);
}
}else {
for (int i=0; i<8; i++){
digitalWrite(DataTrk, disp[trkDigit2][i]);//Turn on selected 7 segments for 2nd digit
digitalWrite(ClockTrk, HIGH);
digitalWrite(ClockTrk, LOW);
}
for (int i=0; i<8; i++){
digitalWrite(DataTrk, disp[trkDigit1][i]);//Turn on selected 7 segments for 1st digit
digitalWrite(ClockTrk, HIGH);
digitalWrite(ClockTrk, LOW);
}
}
digitalWrite(LatchTrk, HIGH);
digitalWrite(LatchTrk, LOW);
command[0] = 0xAA;// 170
command[1] = 0x08;// 8
command[2] = 0x0F;// 15
command[3] = 0x01;// 1 SD CARD
command[4] = 0x2F;// / = 47
if (fldrNum == 1){
command[5] = 71;// G = 71 = 0x47 Grinch
command[6] = 82;// R = 82 = 0x52
if (lgtCond == 1){
lgtSw(1);
}else{
lgtSw(2);
}
} else if (fldrNum == 2){
command[5] = 0x53;// S = 83 Scrooge
command[6] = 0x47;// G = 71
if (lgtCond == 1){
lgtSw(1);
}else{
lgtSw(3);
}
} else if (fldrNum == 3){
command[5] = 0x45;// E = 69 Elf
command[6] = 0x46;// F = 70
if (lgtCond == 1){
lgtSw(1);
}else{
if (tmp2 == 2){
lgtSw(18);
}else{
lgtSw(4);
}
}
} else if (fldrNum == 4){
command[5] = 0x48;// H = 72 Home Alone
command[6] = 0x41;// A = 65
if (lgtCond == 1){
lgtSw(1);
}else{
lgtSw(5);
}
} else if (fldrNum == 5){
command[5] = 0x48;// H = 72 Polar Express Hobo
command[6] = 0x42;// B = 66
if (lgtCond == 1){
lgtSw(1);
}
} else if (fldrNum == 6){
command[5] = 0x42;// B = 66 Blizzard
command[6] = 0x4C;// L = 76
if (lgtCond == 1){
lgtSw(1);
}
} else if (fldrNum == 7){
command[5] = 0x46;// F = 70 Forest
command[6] = 0x54;// T = 84
if (lgtCond == 1){
lgtSw(1);
}
} else if (fldrNum == 8){
command[5] = 0x4E;// N = 78 North Pole
command[6] = 0x50;// P = 80
if (lgtCond == 1){
lgtSw(1);
}else{
lgtSw(6);
}
} else if (fldrNum == 9){
command[5] = 0x43;// C = 67 Carolers
command[6] = 0x52;// R = 82
if (lgtCond == 1){
lgtSw(1);
}else{
if (tmp2 == 1){
lgtSw(8);
}else{
lgtSw(7);
}
}
} else if (fldrNum == 10){
command[5] = 0x43;// C = 67 Church
command[6] = 0x48;// H = 72
if (lgtCond == 1){
lgtSw(1);
}else{
lgtSw(9);
}
} else if (fldrNum == 11){
command[5] = 0x54;// T = 84 Town Center
command[6] = 0x43;// C = 67
if (lgtCond == 1){
lgtSw(1);
}else{
if (tmp2 == 5){
lgtBlnk();
}else{
lgtSw(11);
}
}
} else if (fldrNum == 12){
command[5] = 0x46;// F = 70 Campfire
command[6] = 0x52;// R = 82
if (lgtCond == 1){
lgtSw(1);
}else{
Campfire();
}
} else if (fldrNum == 13){
command[5] = 0x49;// I = 73 Ice Skating
command[6] = 0x53;// S = 83
if (lgtCond == 1){
lgtSw(1);
}else{
lgtSw(14);
}
} else if (fldrNum == 14){
command[5] = 0x42;// B = 66 Bell Tower
command[6] = 0x54;// T = 84
if (lgtCond == 1){
lgtSw(1);
}else{
lgtSw(17);
}
}
command[7] = 0x2A;// * = 42
command[8] = 0x2F;// / = 47
command[9] = 0x30;// 0 = 48
command[10] = 0x30;// 0 = 48
command[14] = 0x2A;// * = 42
command[15] = 0x4D;// M = 77
command[16] = 0x50;// P = 80
command[17] = 0x33;// 3 = 51
checkSum = 0;
for (int i=0; i<18; i++) {
checkSum += command[i];
}
command[18] = lowByte(checkSum);//SM check bit... low bit of the sum of all previous values
commandLength = 19;
sendCommand(fldrNum);
}
void clrDir(){
for (int i=0; i<16; i++){
digitalWrite(DataSpkr, spkrNumGrpA[16][i]);//Turn all speaker relays off
digitalWrite(ClockSpkr, HIGH);
digitalWrite(ClockSpkr, LOW);
}
digitalWrite(LatchSpkr, HIGH);
digitalWrite(LatchSpkr, LOW);
}
void dirSw(int x){
for (int i=0; i<2; i++){//Set both Folder digits blank
for (int j=0; j<8; j++){
digitalWrite(DataFldr, disp[10][j]);
digitalWrite(ClockFldr, HIGH);
digitalWrite(ClockFldr, LOW);
}
}
digitalWrite(LatchFldr, HIGH);
digitalWrite(LatchFldr, LOW);
int tmp = x;
fldrDigit2 = x%10;//2nd digit of "x"
fldrDigit1 = x /= 10;//1st digit of "x"
if (tmp<10){
for (int i=0; i<8; i++){
digitalWrite(DataFldr, disp[tmp][i]);//Turn on selected 7 segments for 2nd digit
digitalWrite(ClockFldr, HIGH);
digitalWrite(ClockFldr, LOW);
}
for (int i=0; i<8; i++){
digitalWrite(DataFldr, disp[10][i]);//Turn all 7 segments off for 1st digit
digitalWrite(ClockFldr, HIGH);
digitalWrite(ClockFldr, LOW);
}
}else {
for (int i=0; i<8; i++){
digitalWrite(DataFldr, disp[fldrDigit2][i]);//Turn on selected 7 segments for 2nd digit
digitalWrite(ClockFldr, HIGH);
digitalWrite(ClockFldr, LOW);
}
for (int i=0; i<8; i++){
digitalWrite(DataFldr, disp[fldrDigit1][i]);//Turn on selected 7 segments for 1st digit
digitalWrite(ClockFldr, HIGH);
digitalWrite(ClockFldr, LOW);
}
}
digitalWrite(LatchFldr, HIGH);
digitalWrite(LatchFldr, LOW);
clrDir();
Stop();
if (tmp == 5 || tmp>16){
clrDir();
}else if (tmp<5){
for (int i=0; i<16; i++){//For Relays 1-4 *****************************************************************************
digitalWrite(DataSpkr, spkrNumGrpA[tmp-1][i]);//Turn selected speaker relay on
digitalWrite(ClockSpkr, HIGH);
digitalWrite(ClockSpkr, LOW);
}
digitalWrite(LatchSpkr, HIGH);
digitalWrite(LatchSpkr, LOW);
}else {
for (int i=0; i<16; i++){//For Relays 5-16 *****************************************************************************
digitalWrite(DataSpkr, spkrNumGrpA[tmp-2][i]);//Turn selected speaker relay on
digitalWrite(ClockSpkr, HIGH);
digitalWrite(ClockSpkr, LOW);
}
digitalWrite(LatchSpkr, HIGH);
digitalWrite(LatchSpkr, LOW);
}
}
void setup() {
Serial.begin(115200);
Serial1.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);
delay(250);
for (int i=0; i<23; i++){
pinMode(pinBtn[i], INPUT);
}
pinMode(busyPin1, INPUT);
pinMode(busyPin2, INPUT);
pinMode(busyPin3, INPUT);
pinMode(lgtAll, INPUT);
pinMode(dblSound, INPUT);
pinMode(busyLed1, OUTPUT);
pinMode(busyLed2, OUTPUT);
pinMode(busyLed3, OUTPUT);
pinMode(DataFldr, OUTPUT);
pinMode(LatchFldr, OUTPUT);
pinMode(ClockFldr, OUTPUT);
pinMode(DataTrk, OUTPUT);
pinMode(LatchTrk, OUTPUT);
pinMode(ClockTrk, OUTPUT);
pinMode(DataSpkr, OUTPUT);
pinMode(LatchSpkr, OUTPUT);
pinMode(ClockSpkr, OUTPUT);
pinMode(DataLgt, OUTPUT);
pinMode(LatchLgt, OUTPUT);
pinMode(ClockLgt, OUTPUT);
digitalWrite(busyLed1, LOW);
digitalWrite(busyLed2, LOW);
digitalWrite(busyLed3, LOW);
clrDir();
clrLght();
setVol();
}
void loop() {
busyPinState1 = digitalRead(busyPin1);
busyPinState2 = digitalRead(busyPin2);
busyPinState3 = digitalRead(busyPin3);
lgtState = digitalRead(lgtAll);
dblState = digitalRead(dblSound);
for (int i=0; i<23; i++){
valNum[i] = digitalRead(pinBtn[i]);
}
if (busyPinState1 > 0) { //nothing playing on Board 1
digitalWrite(busyLed1, LOW);
} else {
digitalWrite(busyLed1, HIGH);
}
if (busyPinState2 > 0) { //nothing playing on Board 2
digitalWrite(busyLed2, LOW);
} else {
digitalWrite(busyLed2, HIGH);
}
if (busyPinState3 > 0) { //nothing playing on Board 3
digitalWrite(busyLed3, LOW);
} else {
digitalWrite(busyLed3, HIGH);
}
if (valNum[21] == HIGH){
delay(250);
upVol();
}
if (valNum[22] == HIGH){
delay(250);
dwnVol();
}
if(dblState == HIGH && busyPinState3 == HIGH){
}
if (valNum[0] == HIGH){
for (int j=1; j<21; j++){
if (valNum[j] == HIGH){
sndFldr = j;
delay(250);
clrTrk();
dirSw(j);
}
}
}else{
if (valNum[1] == HIGH || valNum[2] == HIGH || valNum[3] == HIGH || valNum[4] == HIGH || valNum[5] == HIGH || valNum[6] == HIGH || valNum[7] == HIGH || valNum[8] == HIGH || valNum[9] == HIGH || valNum[10] == HIGH || valNum[11] == HIGH || valNum[12] == HIGH || valNum[13] == HIGH || valNum[14] == HIGH || valNum[15] == HIGH || valNum[16] == HIGH || valNum[17] == HIGH || valNum[18] == HIGH || valNum[19] == HIGH || valNum[20] == HIGH){
for (int k=1; k<21; k++){// for tracks 1 - 20
if (valNum[k] == HIGH){
delay(250);
trkPlay(sndFldr,k,lgtState);
}
}
}
}
}