Hallo, katanya ini video kelanjutan dari part 1 yang berjudul Elektronika Dasar. Namun terlihat sangat kalau video pertama itu receh banget, di mana intro yang sangat meng-halibiru waktu.
Saya harap di video ke dua ini bisa memberi edukasi, meskipun 1% ..
//mp3 player declarate project
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
String getVoice(int val);
//analog declarate project
int getBuffer[15];
int l, analGet, anal2;
int count_occur(int a[], char map[], int num_elements, int start);
void setup() {
mySoftwareSerial.begin(9600);
Serial.begin(9600);
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println("Gagal initialisasi module");
}
myDFPlayer.volume(25);
Serial.print("Setup = ");
anal2 = analogRead(A2);
Serial.println(anal2);
Serial.print("Normalisasi = ");
anal2 = anal2 - 512;
Serial.println(anal2);
}
void loop() {
int value = analogRead(A1)-anal2;
if (value > 500 ){
l++;
if(l == 15){
char map[20] = {0};
int num_occ;
for (int position = 0; position < 20; position++){
if (map[position] == 0) {
num_occ = count_occur(getBuffer, map, 20, position);
if (num_occ > 4){
analGet = getBuffer[position];
}
}
}
Serial.print("Found {");
Serial.print(analGet);
Serial.println("} ");
Serial.println(getVoice(analGet));
}else if(l > 15 ){
//Serial.print(value);
Serial.println("Stop read ...");
}else{
getBuffer[l] = value;
Serial.print(value);
Serial.println(" Read buffer ....");
}
}else{
l = 0;
analGet = 0;
}
}
int count_occur(int a[], char map[], int num_elements, int start) {
int i, count = 0, value = a[start];
for (i = start; i < num_elements; i++){
if (a[i] == value){
map[i] = 1;
++count;
}
}
return (count);
}
String getVoice(int val){
String outs = "Kosong";
if(811 <= val && 815 >= val){
myDFPlayer.play(1);
outs = "A";
}else if(817 <= val && 821 >= val){
myDFPlayer.play(2);
outs = "B";
}else if(824 <= val && 828 >= val){
myDFPlayer.play(3);
outs = "C";
}else if(831 <= val && 835 >= val){
myDFPlayer.play(4);
outs = "D";
}else if(838 <= val && 841 >= val){
myDFPlayer.play(5);
outs = "E";
}else if(534 <= val && 537 >= val){
outs = "F";
}else if(547 <= val && 549 >= val){
outs = "G";
}else if(560 <= val && 564 >= val){
outs = "H";
}else if(574 <= val && 577 >= val){
outs = "I";
}else if(590 <= val && 593 >= val){
outs = "J";
}else if(608 <= val && 610 >= val){
outs = "K";
}else if(622 <= val && 625 >= val){
outs = "L";
}
return outs;
}