-
Notifications
You must be signed in to change notification settings - Fork 0
/
PT2314.ino
165 lines (147 loc) · 5.45 KB
/
PT2314.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Project : LaLiMat project (https://www.youtube.com/playlist?list=PLJBKmE2nNweRXOebZjydkMEiq2pHtBMOS in Chinese)
file : PT2314.ino
Author : ykchau
youtube : youtube.com/ykchau888
Licenese : GPL-3.0
Please let me know if you use it commercial project.
*/
#include "PT2314.h"
#include <Wire.h>
PT2314 AudioControl;
String str;
byte value = 0;
byte loudness[] = { PT2314_LOUDNESS_ON, PT2314_LOUDNESS_OFF };
byte gain[] = { PT2314_GAIN_0, PT2314_GAIN_3_75, PT2314_GAIN_7_5, PT2314_GAIN_11_25 };
void setup() {
Wire.begin();
Serial.begin(115200);
AudioControl.switchChannel(PT2314_CHANNEL_1, PT2314_LOUDNESS_OFF, PT2314_GAIN_0);
AudioControl.setVolume(15);
AudioControl.setBass(7);
AudioControl.setTreble(7);
AudioControl.setAttenuation(PT2314_SPEAKER_LEFT,15);
AudioControl.setAttenuation(PT2314_SPEAKER_RIGHT,15);
// If there have no output at the initial stage, just run this command one more time
AudioControl.switchChannel(PT2314_CHANNEL_1, PT2314_LOUDNESS_OFF, PT2314_GAIN_0);
}
void loop() {
if ( Serial.available() ) {
str = Serial.readStringUntil('\n');
switch (str.charAt(0)) {
case '1':
AudioControl.switchChannel(PT2314_CHANNEL_1, AudioControl.settings.loudness, AudioControl.settings.gain);
printChannel();
break;
case '2':
AudioControl.switchChannel(PT2314_CHANNEL_2, AudioControl.settings.loudness, AudioControl.settings.gain);
printChannel();
break;
case '3':
AudioControl.switchChannel(PT2314_CHANNEL_3, AudioControl.settings.loudness, AudioControl.settings.gain);
printChannel();
break;
case '4':
AudioControl.switchChannel(PT2314_CHANNEL_4, AudioControl.settings.loudness, AudioControl.settings.gain);
printChannel();
break;
case 'v':
Serial.println("Please enter volume : small (0 - 100) big");
readValue();
AudioControl.setVolume(value);
printVolume();
break;
case 'b':
Serial.println("Please enter bass : small (0 - 100) big");
readValue();
AudioControl.setBass(value);
printBass();
break;
case 't':
Serial.println("Please enter Treble : small (0 - 100) big");
readValue();
AudioControl.setTreble(value);
printTreble();
break;
case 'l':
Serial.println("Please enter Att L : small (0 - 100) big");
readValue();
AudioControl.setAttenuation(PT2314_SPEAKER_LEFT, value);
printAttL();
break;
case 'r':
Serial.println("Please enter ATT R : small (0 - 100) big");
readValue();
AudioControl.setAttenuation(PT2314_SPEAKER_RIGHT, value);
printAttR();
break;
case 'g': // Gain
Serial.println("Please enter gain (0 - 3, [0, 3.75, 7.5, 11.25]): ");
readValue();
AudioControl.switchChannel(AudioControl.settings.channel, AudioControl.settings.loudness, gain[value]);
printChannel();
break;
case 'c': // Channel
Serial.println("Please enter channel (1 - 4) : ");
readValue();
AudioControl.switchChannel(value - 1, AudioControl.settings.loudness, AudioControl.settings.gain);
printChannel();
break;
case 'o': // Loudness
Serial.println("Please enter loudness (0 - ON, 1 - OFF): ");
readValue();
AudioControl.switchChannel(AudioControl.settings.channel, loudness[value], AudioControl.settings.gain);
printChannel();
break;
case 'e':
SPL("Please SE", "(0 ~ 4, Normal, Classic, Pop, Rock, Jazz)");
readValue();
AudioControl.setSoundEffect(value);
break;
case '`':
AudioControl.printSettings();
break;
case ',':
SPL("Mute Channel Left"," ");
AudioControl.setMute(PT2314_SPEAKER_LEFT, (AudioControl.settings.mute_L == PT2314_MUTE_ON)? PT2314_MUTE_OFF : PT2314_MUTE_ON);
break;
case '.':
SPL("Mute Channel Right"," ");
AudioControl.setMute(PT2314_SPEAKER_RIGHT, (AudioControl.settings.mute_R == PT2314_MUTE_ON)? PT2314_MUTE_OFF : PT2314_MUTE_ON);
break;
default:
break;
}
}
}
void readValue() {
while ( !Serial.available() ) {
continue;
}
str = Serial.readStringUntil('\n');
value = byte(str.toInt());
}
void printVolume() {
SPL("[RAW] Volume : ", AudioControl.settings.volume);
}
void printTreble() {
SPL("[RAW] Treble : ", AudioControl.settings.treble);
}
void printBass() {
SPL("[RAW] Bass : ", AudioControl.settings.bass);
}
void printAttL() {
SPL("[RAW] Att L : ", AudioControl.settings.attenuation_L);
}
void printAttR() {
SPL("[RAW] Att R : ", AudioControl.settings.attenuation_R);
}
void printChannel() {
SPL("[RAW] Channel : ", AudioControl.settings.channel);
}
void printLoudness() {
SPL("[RAW] Loudness : ", AudioControl.settings.loudness);
}
void printGain() {
SPL("[RAW] Gain : ", AudioControl.settings.gain);
}