#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include <LiquidCrystal_I2C.h>// LCD Library and variables
LiquidCrystal_I2C lcd(0x27,16,2);
int lcdLED = 3; // brignes of the LCD
int bright; // To store the screen brightness
SoftwareSerial mySoftwareSerial(10,11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
int analogPin0 = A0; // Or any pin you are using
int analogPin1 = A1; // Or any pin you are using
int analogPin2 = A2; // Or any pin you are using
String song;
String dog;
String mydog;
void setup()
{
// initialize the lcd
bright =70;// brignes of the LCD
analogWrite(lcdLED, bright);// brignes of the LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.println("Loading... ");
mySoftwareSerial.begin(9600);
Serial.begin(9600);
if (!myDFPlayer.begin(mySoftwareSerial)) //Use softwareSerial to communicate with mp3.
{
lcd.println("Unable to begin:");
while(true);
}
myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
myDFPlayer.volume(20); //Set volume value (0~30).
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.println("good to go ");
}
String PAW (String dog)//PRINT THE NAME OF THE DOG
{
lcd.init();
lcd.setCursor(0,0);
lcd.print(dog);
MP3(dog);
delay(50);
mydog =""; //Zero mydog variable
return dog; // return the name of the dog to the main program
}
void TYPE( String key, String dog) // print the keyboar imput and compares to the dog name
{
lcd.setCursor(0,1);
lcd.print(mydog);
lcd.print(key);
if (key == "DEL") //delete last character of the string mydog
{
int mydoglenght = mydog.length(); // Check the lenght of the string mydog
mydoglenght =mydoglenght-1;
mydog.remove(mydoglenght, 1);
lcd.setCursor(0,1);
lcd.print(mydog);
lcd.print(" " );
}
else{ // Add character to the string mydog
mydog= mydog+key;
}
delay(500);
if (mydog == dog)
{
lcd.print(" MOLT BE" ); // Positive message
myDFPlayer.play(35);
pinMode(9, HIGH);
delay(500);
}
}
void MP3 (String mp3Command)
{
if (mp3Command == "volumeup") {myDFPlayer.volumeUp();}
if (mp3Command == "volumedown"){myDFPlayer.volumeDown();}
if (mp3Command == "pause") {myDFPlayer.pause(); }
if (mp3Command == "STOP") {myDFPlayer.stop(); }
if (mp3Command == "previous") {myDFPlayer.previous(); }
if (mp3Command == "next") {myDFPlayer.next();}
if (mp3Command == "play") {myDFPlayer.next(); lcd.print("play");}
// Specific song tracks with the voice of the cartacters
if (mp3Command == "PAW PATROL") {myDFPlayer.play(24);}
if (mp3Command == "CHASE") {myDFPlayer.play(5);}
if (mp3Command == "RUBBLE") {myDFPlayer.play(28);}
if (mp3Command == "EVEREST") {myDFPlayer.play(14);}
if (mp3Command == "ROCKY") {myDFPlayer.play(10);}
if (mp3Command == "ZUMA") {myDFPlayer.play(14);}
if (mp3Command == "SKYE") {myDFPlayer.play(31);}
if (mp3Command == "TRACKER") {myDFPlayer.play(14);}
delay(100);
}
void show (String key) //Other functions on the keyboard
{
//Clear Screen
if (key == "CLR")
{
lcd.init();
lcd.setCursor(0,0);
}
//BRIGHTNES UP Screen
if (key == "UP")
{
bright =bright +10;
analogWrite(lcdLED, bright);// brignes of the LCD
delay(200);
}
//BRIGHTNES DOWN Screen
if (key == "DOWN") //Clear Screen
{
bright =bright -10;
analogWrite(lcdLED, bright);// brignes of the LCD
delay(200);
}
}
void loop(){
int val0 = 0; // an auxiliar variable to store the value
int val1 = 0; // an auxiliar variable to store the value
int val2 = 0; // an auxiliar variable to store the value
char key= ("");
val0 = analogRead (analogPin0); //4x4 kepay 2
if (val0 >= 1020 and val0 <= 1024){dog=PAW("PAW PATROL");};
if (val0 >= 925 and val0 <= 935){dog=PAW("CHASE");};
if (val0 >= 845 and val0 <= 855){dog=PAW("MARSHALL");};
if (val0 >= 785 and val0 <= 795){dog=PAW("RUBBLE");};
if (val0 >= 675 and val0 <= 685){TYPE("Q" ,dog);};
if (val0 >= 630 and val0 <= 640){TYPE("W" ,dog);};
if (val0 >= 595 and val0 <= 605){TYPE("E" ,dog);};
if (val0 >= 560 and val0 <= 570){TYPE("R" ,dog);};
if (val0 >= 500 and val0 <= 510){key = ("OK");myDFPlayer.play(14);};
if (val0 >= 480 and val0 <= 490){TYPE("A" ,dog);};
if (val0 >= 450 and val0 <= 460){TYPE("S" ,dog);};
if (val0 >= 435 and val0 <= 445){TYPE("D" ,dog);};
if (val0 >= 400 and val0 <= 410){MP3("previous");};
if (val0 >= 320 and val0 <= 330){MP3("next");};
if (val0 >= 265 and val0 <= 275){TYPE("Z" ,dog);};
if (val0 >= 233 and val0 <= 243){TYPE("X" ,dog);};
val1 = analogRead (analogPin1); //4x4 keypad 1
if (val1 >= 1020 and val1 <= 1024){dog=PAW("EVEREST");};
if (val1 >= 925 and val1 <= 935){dog=PAW("ROCKY");};
if (val1 >= 845 and val1 <= 855){dog=PAW("ZUMA");};
if (val1 >= 785 and val1 <= 795){dog=PAW("SKYE");};
if (val1 >= 675 and val1 <= 685){TYPE("T" ,dog);};
if (val1 >= 630 and val1 <= 640){TYPE("Y" ,dog);};
if (val1 >= 595 and val1 <= 605){TYPE("U" ,dog);};
if (val1 >= 560 and val1 <= 570){TYPE("I" ,dog);};
if (val1 >= 500 and val1 <= 510){TYPE("F" ,dog);};
if (val1 >= 480 and val1 <= 490){TYPE("G" ,dog);};
if (val1 >= 450 and val1 <= 460){TYPE("H" ,dog);};
if (val1 >= 435 and val1 <= 445){TYPE("J" ,dog);};
if (val1 >= 400 and val1 <= 410){TYPE("C" ,dog);};
if (val1 >= 320 and val1 <= 330){TYPE("V" ,dog);};
if (val1 >= 265 and val1 <= 275){TYPE("B" ,dog);};
if (val1 >= 233 and val1 <= 243){TYPE("N" ,dog);};
val2 = analogRead (analogPin2); //3x4 keypad
if (val2 >= 1020 and val2 <= 1024){dog=PAW("TRACKER");};
if (val2 >= 925 and val2<= 935){TYPE("DEL",dog);myDFPlayer.play(6);};
if (val2 >= 845 and val2<= 855){show("CLR");myDFPlayer.play(32);};
if (val2 >= 785 and val2<= 795){TYPE("O" ,dog);};
if (val2 >= 725 and val2 <= 735){TYPE("P",dog);};
if (val2 >= 675 and val2 <=685 ){show("UP");};
if (val2 >= 640 and val2 <= 645){TYPE("K",dog);};
if (val2 >= 600 and val2 <= 610){TYPE("L",dog);};
if (val2 >= 565 and val2<= 575){show("DOWN");};
if (val2 >= 530 and val2 <= 550){TYPE("M",dog);};
if (val2 >= 500 and val2<=515){TYPE(" ",dog);};
if (val2 >= 485 and val2<=495){myDFPlayer.play(17);};
}
Comments