1#include "SoftwareSerial.h"
2#include <LiquidCrystal_I2C.h>
3
4SoftwareSerial playerSerial(10, 11);
5LiquidCrystal_I2C lcd (0x26, 16, 2);
6
7# define Start_Byte 0x7E
8# define Version_Byte 0xFF
9# define Command_Length 0x06
10# define End_Byte 0xEF
11# define Acknowledge 0x00
12# define ACTIVATED LOW
13
14
15int touchCount = 0;
16int currTrack = 0;
17
18
19String lcdText = "Enter the Wu-tang";
20
21String trackName[11] = {"Bring Da Ruckus", "Shame On a ", "Clan In Da Front", "Wu-Tang: 7th Chamber", "Can It Be All So Simple", "Da Mystery of Chessboxin'", "Wu-Tang Clain Ain't Nuthin ta F' Wit", "C.R.E.A.M", "Method Man", "Protect Ya Neck", "Tearz"};
22
23void setup()
24{
25
26 Serial.begin(9600);
27 playerSerial.begin(9600);
28
29
30 pinMode(8, INPUT);
31
32
33 lcd.init();
34 lcd.clear();
35 lcd.backlight();
36
37
38
39 execute_CMD(0x11, 0, 0);
40 delay(500);
41
42 execute_CMD(0x06, 0, 30);
43 delay(500);
44}
45
46void doAudio(){
47 if(touchCount > 5){
48
49 execute_CMD(0x0C, 0, 0);
50 touchCount = 0;
51 currTrack = 0;
52 lcdText = "Enter the Wu-tang";
53 }
54
55 else{
56 switch (touchCount){
57 case 1:
58
59 execute_CMD(0x0D,0,1);
60 delay(1000);
61
62 touchCount = 0;
63
64 lcd.clear();
65 lcdText = trackName[currTrack];
66 break;
67
68 case 2:
69
70 execute_CMD(0x01, 0, 0);
71 delay(1000);
72 touchCount = 0;
73 currTrack++;
74 lcd.clear();
75 lcdText = trackName[currTrack];
76 break;
77
78 case 3:
79
80 execute_CMD(0x02, 0, 0);
81 delay(1000);
82 touchCount = 0;
83 currTrack--;
84 lcd.clear();
85 lcdText = trackName[currTrack];
86 break;
87 }
88 }
89
90}
91
92void loop()
93{
94
95
96 lcd.setCursor(0, 1);
97
98 lcd.print(lcdText);
99
100 lcd.command(0x18);
101
102 delay(150);
103
104
105 if(currTrack > 11){
106 currTrack = 0;
107 }
108
109
110 if(digitalRead(8) == HIGH) {
111 touchCount++;
112 }
113 else{
114
115 doAudio();
116 }
117
118
119 Serial.println(touchCount);
120}
121
122
123
124void execute_CMD(byte CMD, byte Par1, byte Par2)
125
126{
127
128word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
129
130byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
131Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
132
133for (byte k=0; k<10; k++)
134{
135playerSerial.write( Command_line[k]);
136}
137
138}