Components and supplies
Li-Ion Battery 1000mAh
ILI9341
Arduino Mega 2560
Speaker: 0.25W, 8 ohms
DFPlayer - A Mini MP3 Player
3.7V 4.2V Charger & 5V 6V 9V 12V Discharger Board DC DC Converter Boost Module for UPS mobile power 18650 lithium battery
Flash Memory Card, SD Card
DC 5-12V NE555 Switch Module Relay Shield Timer 0-150 Second Adjustable L2KD
Alphanumeric LCD, 16 x 2
Switch Actuator, Head for spring return push-button
Project description
Code
The code for the spelling game
arduino
This game shows a picture on the ILI9341. On the keyboard, there are 10 drawings. After pressing one of those keys a Picture of the animal appears on the screen, the name is written on the LCS 16x2, and a track with the sound plays on the mp3. Then after you type it on the keyboard if the name is correct it sounds music to celebrate .
1 2//LCD 3#include <ILI9341_kbv.h> // This library has been modified 4ILI9341_kbv my_lcd; 5#define vali0 0 6 7 8//SD CARD 9#include <SD.h> 10#define TFT_SD 47 //SC_CS 11Sd2Card card; 12SdVolume volume; 13SdFile root; 14 15//MP3 Mini 16#include "DFRobotDFPlayerMini.h" 17//#include "Arduino.h" 18#include "SoftwareSerial.h" 19SoftwareSerial mySoftwareSerial(7,6); // RX, TX 20DFRobotDFPlayerMini myDFPlayer; 21 22//LCD 2 lines 23#include <LiquidCrystal_I2C.h>// LCD Library and variables 24LiquidCrystal_I2C lcd(0x27,16,2); 25int lcdLED = 3; // brignes of the LCD 26int bright; // To store the screen brightness 27 28//TFT Touch Library 29#include <LCDWIKI_TOUCH.h> 30LCDWIKI_TOUCH my_tft(44,52,50,51,46); //tcs,tclk (sharing with LCD),tdout (MISO) ,tdin (MOSI) ,tirq 31 32 33 34//Folder on the SD card to keep the pictures 35String FOLDERROOT = ""; // I have no folder because all the pictures are on the root of the SD 36uint8_t max_img = 40; 37uint8_t image_counter = 0; 38unsigned long auxtimer, colortimer; 39 40 41//KEYPAD 42 43int analogPin0 = A0; // Or any pin you are using 44int analogPin1 = A1; // Or any pin you are using 45int analogPin2 = A2; // Or any pin you are using 46 47//Aux Global variables 48String song; 49String dog; 50String mydog; 51 52 53 54void setup() 55 { 56 Serial.begin(9600); 57 //Initiate LCD big screen 58 my_lcd.begin(); 59 my_lcd.setRotation(3);// Landscape 60 my_lcd.fillScreen(TFT_PINK);// set color iitial screen 61 //Initiate the Touch capabilities 62 SD.begin(TFT_SD); 63 my_tft.TP_Init(1,240,320); //Define the values for my_lcd ( rotation,With,Height) 64 65 // initialize the lcd 66 Serial.print("\ 67Initializing LCD..."); 68 bright =70;// brignes of the LCD 69 analogWrite(lcdLED, bright);// brignes of the LCD 70 lcd.init(); 71 lcd.backlight(); 72 lcd.setCursor(0,0); 73 lcd.println("Loading... "); 74 75 //Inicialize mp3 76 Serial.print("\ 77Initializing MP3..."); 78 mySoftwareSerial.begin(9600); 79 if (!myDFPlayer.begin(mySoftwareSerial)) //Use softwareSerial to communicate with mp3. 80 { 81 lcd.println("Unable to begin:"); 82 // while(true); //wait until fixed 83 } 84 myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms 85 myDFPlayer.volume(25); //Set volume value (0~30). 86 myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); 87 myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); 88 89 //All good 90 91 //Fist picture 92 Serial.print("\ 93Initializing BMP..."); 94 String filename ="pp_1.bmp"; 95 int len = 30; 96 char pepito[len]; 97 filename.toCharArray(pepito, len); 98 bmpDraw(pepito , 0, 0); 99 lcd.init(); 100 lcd.backlight(); 101 lcd.setCursor(0,0); 102 myDFPlayer.play(28); 103 lcd.println("good to go "); 104 105 } 106 107 108// Makes an Array out of a BMP 109void bmp (String filename){ 110 int len = 30; 111 char pepito[len]; 112 filename.toCharArray(pepito, len); 113 bmpDraw(pepito , 0, 0);} 114 115 116 117String PAW (String dog)//PRINT THE NAME OF THE DOG 118 { 119 lcd.init(); 120 lcd.setCursor(0,0); 121 lcd.print(dog); 122 MP3(dog); 123 delay(50); 124 mydog =""; //Zero mydog variable 125 return dog; // return the name of the dog to the main program 126 } 127 128void TYPE( String key, String dog) // print the keyboar imput and compares to the dog name 129 { 130 lcd.setCursor(0,1); 131 lcd.print(mydog); 132 lcd.print(key); 133 if (key == "DEL") //delete last character of the string mydog 134 { 135 int mydoglenght = mydog.length(); // Check the lenght of the string mydog 136 mydoglenght =mydoglenght-1; 137 mydog.remove(mydoglenght, 1); 138 lcd.setCursor(0,1); 139 lcd.print(mydog); 140 lcd.print(" " ); 141 } 142 else{ // Add character to the string mydog 143 mydog= mydog+key; 144 } 145 delay(500); 146 if (mydog == dog) 147 { 148 lcd.print(" GREAT" ); // Positive message 149 myDFPlayer.play(35); 150 pinMode(9, HIGH); 151 delay(500); 152 } 153 154 155 156 } 157 158 159 160void MP3 (String mp3Command) 161 { 162 163 164 if (mp3Command == "volumeup") {myDFPlayer.volumeUp();} 165 if (mp3Command == "volumedown"){myDFPlayer.volumeDown();} 166 if (mp3Command == "pause") {myDFPlayer.pause(); } 167 if (mp3Command == "STOP") {myDFPlayer.stop(); } 168 if (mp3Command == "previous") {myDFPlayer.previous(); } 169 if (mp3Command == "next") {myDFPlayer.next();} 170 if (mp3Command == "play") {myDFPlayer.next(); lcd.print("play");} 171 172 // Specific song tracks with the voice of the cartacters 173 if (mp3Command == "PAW PATROL") {myDFPlayer.play(22);} 174 if (mp3Command == "CHASE") {myDFPlayer.play(4);} 175 if (mp3Command == "MARSHALL") {myDFPlayer.play(13);} 176 if (mp3Command == "RUBBLE") {myDFPlayer.play(27);} 177 if (mp3Command == "EVEREST") {myDFPlayer.play(14);} 178 if (mp3Command == "ROCKY") {myDFPlayer.play(10);} 179 if (mp3Command == "ZUMA") {myDFPlayer.play(14);} 180 if (mp3Command == "SKYE") {myDFPlayer.play(30);} 181 if (mp3Command == "TRACKER") {myDFPlayer.play(14);} 182 if (mp3Command == "THEME") {myDFPlayer.play(35);} 183 184 delay(100); 185 } 186 187 188 189void show (String key) //Other functions on the keyboard 190 { 191 192 //Clear Screen 193 if (key == "CLR") 194 { 195 lcd.init(); 196 lcd.setCursor(0,0); 197 mydog =""; //Zero mydog variable 198 } 199 //BRIGHTNES UP Screen 200 if (key == "UP") 201 { 202 bright =bright +10; 203 analogWrite(lcdLED, bright);// brignes of the LCD 204 delay(200); 205 } 206 //BRIGHTNES DOWN Screen 207 if (key == "DOWN") //Clear Screen 208 { 209 bright =bright -10; 210 analogWrite(lcdLED, bright);// brignes of the LCD 211 delay(200); 212 } 213 } 214 215void loop(){ 216 217int val0 = 0; // an auxiliar variable to store the value 218int val1 = 0; // an auxiliar variable to store the value 219int val2 = 0; // an auxiliar variable to store the value 220 221 char key= (""); 222 223 val0 = analogRead (analogPin0); //4x4 kepay 2 224 if (val0 >= 1020 and val0 <= 1024){dog=PAW("PAW PATROL");bmp("pp_1.bmp");}; 225 if (val0 >= 925 and val0 <= 935){dog=PAW("CHASE");bmp("pp_8.bmp");}; 226 if (val0 >= 845 and val0 <= 855){dog=PAW("MARSHALL");bmp("pp_9.bmp");}; 227 if (val0 >= 785 and val0 <= 795){dog=PAW("RUBBLE");bmp("pp3.bmp");}; 228 if (val0 >= 675 and val0 <= 685){TYPE("Q" ,dog);}; 229 if (val0 >= 630 and val0 <= 640){TYPE("W" ,dog);}; 230 if (val0 >= 595 and val0 <= 605){TYPE("E" ,dog);}; 231 if (val0 >= 560 and val0 <= 570){TYPE("R" ,dog);}; 232 if (val0 >= 500 and val0 <= 510){key = ("OK");myDFPlayer.play(14);delay(500);}; 233 if (val0 >= 480 and val0 <= 490){TYPE("A" ,dog);}; 234 if (val0 >= 450 and val0 <= 460){TYPE("S" ,dog);}; 235 if (val0 >= 435 and val0 <= 445){TYPE("D" ,dog);}; 236 if (val0 >= 400 and val0 <= 410){MP3("volumeup");}; 237 if (val0 >= 320 and val0 <= 330){MP3("volumedown");}; 238 if (val0 >= 265 and val0 <= 275){TYPE("Z" ,dog);}; 239 if (val0 >= 233 and val0 <= 243){TYPE("X" ,dog);}; 240 241 val1 = analogRead (analogPin1); //4x4 keypad 1 242 if (val1 >= 1020 and val1 <= 1024){dog=PAW("EVEREST");bmp("pp_10.bmp");}; 243 if (val1 >= 925 and val1 <= 935){dog=PAW("ROCKY");bmp("pp_22.bmp");}; 244 if (val1 >= 845 and val1 <= 855){dog=PAW("ZUMA");bmp("pp_6.bmp");}; 245 if (val1 >= 785 and val1 <= 795){dog=PAW("SKYE");bmp("pp_55.bmp");}; 246 if (val1 >= 675 and val1 <= 685){TYPE("T" ,dog);}; 247 if (val1 >= 630 and val1 <= 640){TYPE("Y" ,dog);}; 248 if (val1 >= 595 and val1 <= 605){TYPE("U" ,dog);}; 249 if (val1 >= 560 and val1 <= 570){TYPE("I" ,dog);}; 250 if (val1 >= 500 and val1 <= 510){TYPE("F" ,dog);}; 251 if (val1 >= 480 and val1 <= 490){TYPE("G" ,dog);}; 252 if (val1 >= 450 and val1 <= 460){TYPE("H" ,dog);}; 253 if (val1 >= 435 and val1 <= 445){TYPE("J" ,dog);}; 254 if (val1 >= 400 and val1 <= 410){TYPE("C" ,dog);}; 255 if (val1 >= 320 and val1 <= 330){TYPE("V" ,dog);}; 256 if (val1 >= 265 and val1 <= 275){TYPE("B" ,dog);}; 257 if (val1 >= 233 and val1 <= 243){TYPE("N" ,dog);}; 258 259 val2 = analogRead (analogPin2); //3x4 keypad 260 if (val2 >= 1020 and val2 <= 1024){dog=PAW("TRACKER");bmp("pp_44.bmp");}; 261 if (val2 >= 925 and val2<= 935){TYPE("DEL",dog);myDFPlayer.play(6);}; 262 if (val2 >= 845 and val2<= 855){show("CLR");myDFPlayer.play(32);bmp("pp3.bmp");}; 263 if (val2 >= 785 and val2<= 795){TYPE("O" ,dog);}; 264 if (val2 >= 725 and val2 <= 735){TYPE("P",dog);}; 265 if (val2 >= 675 and val2 <=685 ){show("UP");}; 266 if (val2 >= 635 and val2 <= 645){TYPE("K",dog);}; 267 if (val2 >= 600 and val2 <= 610){TYPE("L",dog);}; 268 if (val2 >= 565 and val2<= 575){show("DOWN");}; 269 if (val2 >= 530 and val2 <= 550){TYPE("M",dog);}; 270 if (val2 >= 500 and val2<=515){TYPE(" ",dog);}; 271 if (val2 >= 485 and val2<=495){myDFPlayer.play(17);delay(500);}; 272 delay(50); 273 //Serial.print(val2); // ESPIA 274 275 276 my_tft.TP_Scan(0); 277 if (my_tft.TP_Get_State()&TP_PRES_DOWN) 278 { 279 bmp("roger.bmp"); 280 delay(1000); 281 my_lcd.fillScreen(TFT_PINK);// set color iitial screen 282 } 283 } 284 285 286 287 288 289uint16_t _read16(File f) { 290 uint16_t result; 291 ((uint8_t *)&result)[0] = f.read(); // LSB 292 ((uint8_t *)&result)[1] = f.read(); // MSB 293 return result; 294} 295 296uint32_t _read32(File f) { 297 uint32_t result; 298 ((uint8_t *)&result)[0] = f.read(); // LSB 299 ((uint8_t *)&result)[1] = f.read(); 300 ((uint8_t *)&result)[2] = f.read(); 301 ((uint8_t *)&result)[3] = f.read(); // MSB 302 return result; 303} 304 305#define BUFFPIXEL 20 306void bmpDraw(char *fileName, int x, int y){ 307 308 File bmpFile; 309 int bmpWidth, bmpHeight; // W+H in pixels 310 uint8_t bmpDepth; // Bit depth (currently must be 24) 311 uint32_t bmpImageoffset; // Start of image data in file 312 uint32_t rowSize; // Not always = bmpWidth; may have padding 313 uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel) 314 315 uint16_t lcdbuffer[BUFFPIXEL]; // pixel out buffer (16-bit per pixel) 316 uint8_t lcdidx = 0; 317 boolean first = true; 318 319 uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer 320 boolean goodBmp = false; // Set to true on valid header parse 321 boolean flip = true; // BMP is stored bottom-to-top 322 int w, h, row, col; 323 uint8_t r, g, b; 324 uint32_t pos = 0, startTime = millis(); 325 326 if((x >= my_lcd.width()) || (y >= my_lcd.height())) return; 327 328 // Open requested file on SD card 329 if ((bmpFile = SD.open(fileName)) == NULL) { 330 Serial.println("File Found??" ); 331 Serial.println( fileName); 332 return; 333 }else{ 334 Serial.println("File Found" ); 335 } 336 337 338 if(_read16(bmpFile) == 0x4D42) { // BMP signature 339 340 (void)_read32(bmpFile); // Read & ignore creator bytes 341 Serial.print("File size: ");Serial.println( _read32(bmpFile) ); 342 bmpImageoffset = _read32(bmpFile); // Start of image data 343 Serial.print(" Header size: ");Serial.println( _read32(bmpFile) ); 344 345 // Read DIB header 346 347 bmpWidth = _read32(bmpFile); 348 bmpHeight = _read32(bmpFile); 349 if(_read16(bmpFile) == 1) { // # planes -- must be '1' 350 bmpDepth = _read16(bmpFile); // bits per pixel 351 352 if((bmpDepth == 24) && (_read32(bmpFile) == 0)) { // 0 = uncompressed 353 354 goodBmp = true; // Supported BMP format -- proceed! 355 356 // BMP rows are padded (if needed) to 4-byte boundary 357 rowSize = (bmpWidth * 3 + 3) & ~3; 358 359 // If bmpHeight is negative, image is in top-down order. 360 // This is not canon but has been observed in the wild. 361 if(bmpHeight < 0) { 362 bmpHeight = -bmpHeight; 363 flip = false; 364 } 365 366 // Crop area to be loaded 367 w = bmpWidth; 368 h = bmpHeight; 369 if((x+w-1) >= my_lcd.width()) w = my_lcd.width() - x; 370 if((y+h-1) >= my_lcd.height()) h = my_lcd.height() - y; 371 372 // Set TFT address window to clipped image bounds 373 my_lcd.setAddrWindow(x, y, x+w-1, y+h-1); 374 375 for (row=0; row<h; row++) { // For each scanline... 376 // Seek to start of scan line. It might seem labor- 377 // intensive to be doing this on every line, but this 378 // method covers a lot of gritty details like cropping 379 // and scanline padding. Also, the seek only takes 380 // place if the file position actually needs to change 381 // (avoids a lot of cluster math in SD library). 382 if(flip) // Bitmap is stored bottom-to-top order (normal BMP) 383 pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize; 384 else // Bitmap is stored top-to-bottom 385 pos = bmpImageoffset + row * rowSize; 386 if(bmpFile.position() != pos) { // Need seek? 387 bmpFile.seek(pos); 388 buffidx = sizeof(sdbuffer); // Force buffer reload 389 } 390 391 for (col=0; col<w; col++) { // For each column... 392 // Time to read more pixel data? 393 if (buffidx >= sizeof(sdbuffer)) { // Indeed 394 // Push LCD buffer to the display first 395 396 if(lcdidx > 0) { 397 my_lcd.pushColors(lcdbuffer, lcdidx, first); 398 lcdidx = 0; 399 first = false; 400 } 401 402 bmpFile.read(sdbuffer, sizeof(sdbuffer)); 403 buffidx = 0; // Set index to beginning 404 } 405 406 // Convert pixel from BMP to TFT format 407 b = sdbuffer[buffidx++]; 408 g = sdbuffer[buffidx++]; 409 r = sdbuffer[buffidx++]; 410 411 lcdbuffer[lcdidx++] = my_lcd.color565(r,g,b); 412 } // end pixel 413 } // end scanline 414 415 if(lcdidx > 0) { 416 my_lcd.pushColors(lcdbuffer, lcdidx, first); 417 } 418 Serial.print("Loaded in: ");Serial.println( millis() - startTime); 419 } // end goodBmp 420 } 421 } 422 423 bmpFile.close(); 424 if(!goodBmp) Serial.println("BMP format not recognized."); 425 } 426 427
The code for the spelling game
arduino
This game shows a picture on the ILI9341. On the keyboard, there are 10 drawings. After pressing one of those keys a Picture of the animal appears on the screen, the name is written on the LCS 16x2, and a track with the sound plays on the mp3. Then after you type it on the keyboard if the name is correct it sounds music to celebrate .
1 2//LCD 3#include <ILI9341_kbv.h> // This library has been modified 4 5ILI9341_kbv my_lcd; 6#define vali0 0 7 8 9//SD CARD 10#include <SD.h> 11#define 12 TFT_SD 47 //SC_CS 13Sd2Card card; 14SdVolume volume; 15SdFile root; 16 17//MP3 18 Mini 19#include "DFRobotDFPlayerMini.h" 20//#include "Arduino.h" 21#include 22 "SoftwareSerial.h" 23SoftwareSerial mySoftwareSerial(7,6); // RX, TX 24DFRobotDFPlayerMini 25 myDFPlayer; 26 27//LCD 2 lines 28#include <LiquidCrystal_I2C.h>// LCD Library 29 and variables 30LiquidCrystal_I2C lcd(0x27,16,2); 31int lcdLED = 3; // brignes 32 of the LCD 33int bright; // To store the screen brightness 34 35//TFT Touch 36 Library 37#include <LCDWIKI_TOUCH.h> 38LCDWIKI_TOUCH my_tft(44,52,50,51,46); 39 //tcs,tclk (sharing with LCD),tdout (MISO) ,tdin (MOSI) ,tirq 40 41 42 43//Folder 44 on the SD card to keep the pictures 45String FOLDERROOT = ""; // I have no folder 46 because all the pictures are on the root of the SD 47uint8_t max_img = 40; 48uint8_t 49 image_counter = 0; 50unsigned long auxtimer, colortimer; 51 52 53//KEYPAD 54 55int 56 analogPin0 = A0; // Or any pin you are using 57int analogPin1 = A1; // Or any 58 pin you are using 59int analogPin2 = A2; // Or any pin you are using 60 61//Aux 62 Global variables 63String song; 64String dog; 65String mydog; 66 67 68 69void 70 setup() 71 { 72 Serial.begin(9600); 73 //Initiate 74 LCD big screen 75 my_lcd.begin(); 76 my_lcd.setRotation(3);// 77 Landscape 78 my_lcd.fillScreen(TFT_PINK);// set color iitial screen 79 80 //Initiate the Touch capabilities 81 SD.begin(TFT_SD); 82 83 my_tft.TP_Init(1,240,320); //Define the values for my_lcd ( rotation,With,Height) 84 85 86 // initialize the lcd 87 Serial.print("\ 88Initializing 89 LCD..."); 90 bright =70;// brignes of the LCD 91 analogWrite(lcdLED, 92 bright);// brignes of the LCD 93 lcd.init(); 94 95 lcd.backlight(); 96 lcd.setCursor(0,0); 97 lcd.println("Loading... 98 "); 99 100 //Inicialize mp3 101 Serial.print("\ 102Initializing 103 MP3..."); 104 mySoftwareSerial.begin(9600); 105 if 106 (!myDFPlayer.begin(mySoftwareSerial)) //Use softwareSerial to communicate with mp3. 107 108 { 109 lcd.println("Unable 110 to begin:"); 111 // while(true); //wait 112 until fixed 113 } 114 myDFPlayer.setTimeOut(500); 115 //Set serial communictaion time out 500ms 116 myDFPlayer.volume(25); 117 //Set volume value (0~30). 118 myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); 119 120 myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); 121 122 123 //All good 124 125 //Fist picture 126 Serial.print("\ 127Initializing 128 BMP..."); 129 String filename ="pp_1.bmp"; 130 131 int len = 30; 132 char pepito[len]; 133 134 filename.toCharArray(pepito, len); 135 bmpDraw(pepito 136 , 0, 0); 137 lcd.init(); 138 lcd.backlight(); 139 140 lcd.setCursor(0,0); 141 myDFPlayer.play(28); 142 lcd.println("good 143 to go "); 144 145 } 146 147 148// Makes an Array 149 out of a BMP 150void bmp (String filename){ 151 int 152 len = 30; 153 char pepito[len]; 154 filename.toCharArray(pepito, 155 len); 156 bmpDraw(pepito , 0, 0);} 157 158 159 160 161String PAW (String dog)//PRINT THE NAME OF THE DOG 162 { 163 164 lcd.init(); 165 lcd.setCursor(0,0); 166 167 lcd.print(dog); 168 MP3(dog); 169 delay(50); 170 mydog 171 =""; //Zero mydog variable 172 return dog; // return the name of the 173 dog to the main program 174 } 175 176void TYPE( String key, 177 String dog) // print the keyboar imput and compares to the dog name 178 { 179 180 lcd.setCursor(0,1); 181 lcd.print(mydog); 182 lcd.print(key); 183 184 if (key == "DEL") //delete last character of the string mydog 185 { 186 187 int mydoglenght = mydog.length(); // Check the lenght of the string 188 mydog 189 mydoglenght =mydoglenght-1; 190 mydog.remove(mydoglenght, 191 1); 192 lcd.setCursor(0,1); 193 lcd.print(mydog); 194 lcd.print(" 195 " ); 196 } 197 else{ // Add character to the string mydog 198 199 mydog= mydog+key; 200 } 201 delay(500); 202 if (mydog 203 == dog) 204 { 205 lcd.print(" GREAT" 206 ); // Positive message 207 myDFPlayer.play(35); 208 pinMode(9, 209 HIGH); 210 delay(500); 211 } 212 213 214 215 216 } 217 218 219 220void MP3 (String mp3Command) 221 { 222 223 224 225 if (mp3Command == "volumeup") {myDFPlayer.volumeUp();} 226 227 if (mp3Command == "volumedown"){myDFPlayer.volumeDown();} 228 if 229 (mp3Command == "pause") {myDFPlayer.pause(); } 230 if (mp3Command 231 == "STOP") {myDFPlayer.stop(); } 232 if (mp3Command == "previous") 233 {myDFPlayer.previous(); } 234 if (mp3Command == "next") {myDFPlayer.next();} 235 236 if (mp3Command == "play") {myDFPlayer.next(); lcd.print("play");} 237 238 239 // Specific song tracks with the voice of the cartacters 240 if 241 (mp3Command == "PAW PATROL") {myDFPlayer.play(22);} 242 if (mp3Command 243 == "CHASE") {myDFPlayer.play(4);} 244 if (mp3Command == "MARSHALL") 245 {myDFPlayer.play(13);} 246 if (mp3Command == "RUBBLE") {myDFPlayer.play(27);} 247 248 if (mp3Command == "EVEREST") {myDFPlayer.play(14);} 249 if 250 (mp3Command == "ROCKY") {myDFPlayer.play(10);} 251 if (mp3Command 252 == "ZUMA") {myDFPlayer.play(14);} 253 if (mp3Command == "SKYE") 254 {myDFPlayer.play(30);} 255 if (mp3Command == "TRACKER") {myDFPlayer.play(14);} 256 257 if (mp3Command == "THEME") {myDFPlayer.play(35);} 258 259 260 delay(100); 261 } 262 263 264 265void show (String key) //Other 266 functions on the keyboard 267 { 268 269 //Clear Screen 270 271 if (key == "CLR") 272 { 273 lcd.init(); 274 275 lcd.setCursor(0,0); 276 mydog =""; //Zero mydog variable 277 278 } 279 //BRIGHTNES UP Screen 280 if (key == "UP") 281 282 { 283 bright =bright +10; 284 analogWrite(lcdLED, bright);// 285 brignes of the LCD 286 delay(200); 287 } 288 //BRIGHTNES DOWN 289 Screen 290 if (key == "DOWN") //Clear Screen 291 { 292 bright 293 =bright -10; 294 analogWrite(lcdLED, bright);// brignes of the LCD 295 delay(200); 296 297 } 298 } 299 300void loop(){ 301 302int val0 = 0; // 303 an auxiliar variable to store the value 304int val1 = 0; // an auxiliar variable 305 to store the value 306int val2 = 0; // an auxiliar variable to store the value 307 308 309 char key= (""); 310 311 val0 = analogRead (analogPin0); //4x4 kepay 2 312 313 if (val0 >= 1020 and val0 <= 1024){dog=PAW("PAW PATROL");bmp("pp_1.bmp");}; 314 315 if (val0 >= 925 and val0 <= 935){dog=PAW("CHASE");bmp("pp_8.bmp");}; 316 317 if (val0 >= 845 and val0 <= 855){dog=PAW("MARSHALL");bmp("pp_9.bmp");}; 318 319 if (val0 >= 785 and val0 <= 795){dog=PAW("RUBBLE");bmp("pp3.bmp");}; 320 321 if (val0 >= 675 and val0 <= 685){TYPE("Q" ,dog);}; 322 if (val0 >= 323 630 and val0 <= 640){TYPE("W" ,dog);}; 324 if (val0 >= 595 and val0 <= 605){TYPE("E" 325 ,dog);}; 326 if (val0 >= 560 and val0 <= 570){TYPE("R" ,dog);}; 327 if 328 (val0 >= 500 and val0 <= 510){key = ("OK");myDFPlayer.play(14);delay(500);}; 329 330 if (val0 >= 480 and val0 <= 490){TYPE("A" ,dog);}; 331 if (val0 >= 450 332 and val0 <= 460){TYPE("S" ,dog);}; 333 if (val0 >= 435 and val0 <= 445){TYPE("D" 334 ,dog);}; 335 if (val0 >= 400 and val0 <= 410){MP3("volumeup");}; 336 if 337 (val0 >= 320 and val0 <= 330){MP3("volumedown");}; 338 if (val0 >= 265 and 339 val0 <= 275){TYPE("Z" ,dog);}; 340 if (val0 >= 233 and val0 <= 243){TYPE("X" 341 ,dog);}; 342 343 val1 = analogRead (analogPin1); //4x4 keypad 1 344 if 345 (val1 >= 1020 and val1 <= 1024){dog=PAW("EVEREST");bmp("pp_10.bmp");}; 346 347 if (val1 >= 925 and val1 <= 935){dog=PAW("ROCKY");bmp("pp_22.bmp");}; 348 349 if (val1 >= 845 and val1 <= 855){dog=PAW("ZUMA");bmp("pp_6.bmp");}; 350 351 if (val1 >= 785 and val1 <= 795){dog=PAW("SKYE");bmp("pp_55.bmp");}; 352 353 if (val1 >= 675 and val1 <= 685){TYPE("T" ,dog);}; 354 if (val1 >= 630 355 and val1 <= 640){TYPE("Y" ,dog);}; 356 if (val1 >= 595 and val1 <= 605){TYPE("U" 357 ,dog);}; 358 if (val1 >= 560 and val1 <= 570){TYPE("I" ,dog);}; 359 if 360 (val1 >= 500 and val1 <= 510){TYPE("F" ,dog);}; 361 if (val1 >= 480 and val1 362 <= 490){TYPE("G" ,dog);}; 363 if (val1 >= 450 and val1 <= 460){TYPE("H" 364 ,dog);}; 365 if (val1 >= 435 and val1 <= 445){TYPE("J" ,dog);}; 366 if 367 (val1 >= 400 and val1 <= 410){TYPE("C" ,dog);}; 368 if (val1 >= 320 and val1 369 <= 330){TYPE("V" ,dog);}; 370 if (val1 >= 265 and val1 <= 275){TYPE("B" 371 ,dog);}; 372 if (val1 >= 233 and val1 <= 243){TYPE("N" ,dog);}; 373 374 375 val2 = analogRead (analogPin2); //3x4 keypad 376 if (val2 >= 1020 and val2 377 <= 1024){dog=PAW("TRACKER");bmp("pp_44.bmp");}; 378 if (val2 >= 925 and 379 val2<= 935){TYPE("DEL",dog);myDFPlayer.play(6);}; 380 if (val2 >= 845 and 381 val2<= 855){show("CLR");myDFPlayer.play(32);bmp("pp3.bmp");}; 382 if (val2 383 >= 785 and val2<= 795){TYPE("O" ,dog);}; 384 if (val2 >= 725 and val2 <= 735){TYPE("P",dog);}; 385 386 if (val2 >= 675 and val2 <=685 ){show("UP");}; 387 if (val2 >= 635 and 388 val2 <= 645){TYPE("K",dog);}; 389 if (val2 >= 600 and val2 <= 610){TYPE("L",dog);}; 390 391 if (val2 >= 565 and val2<= 575){show("DOWN");}; 392 if (val2 >= 530 and 393 val2 <= 550){TYPE("M",dog);}; 394 if (val2 >= 500 and val2<=515){TYPE(" ",dog);}; 395 396 if (val2 >= 485 and val2<=495){myDFPlayer.play(17);delay(500);}; 397 delay(50); 398 399 //Serial.print(val2); // ESPIA 400 401 402 my_tft.TP_Scan(0); 403 if (my_tft.TP_Get_State()&TP_PRES_DOWN) 404 405 { 406 bmp("roger.bmp"); 407 delay(1000); 408 my_lcd.fillScreen(TFT_PINK);// 409 set color iitial screen 410 } 411 } 412 413 414 415 416 417uint16_t _read16(File 418 f) { 419 uint16_t result; 420 ((uint8_t *)&result)[0] = f.read(); // LSB 421 ((uint8_t 422 *)&result)[1] = f.read(); // MSB 423 return result; 424} 425 426uint32_t _read32(File 427 f) { 428 uint32_t result; 429 ((uint8_t *)&result)[0] = f.read(); // LSB 430 ((uint8_t 431 *)&result)[1] = f.read(); 432 ((uint8_t *)&result)[2] = f.read(); 433 ((uint8_t 434 *)&result)[3] = f.read(); // MSB 435 return result; 436} 437 438#define BUFFPIXEL 439 20 440void bmpDraw(char *fileName, int x, int y){ 441 442 File bmpFile; 443 444 int bmpWidth, bmpHeight; // W+H in pixels 445 uint8_t bmpDepth; 446 // Bit depth (currently must be 24) 447 uint32_t bmpImageoffset; 448 // Start of image data in file 449 uint32_t rowSize; // 450 Not always = bmpWidth; may have padding 451 uint8_t sdbuffer[3*BUFFPIXEL]; 452 // pixel buffer (R+G+B per pixel) 453 454 uint16_t lcdbuffer[BUFFPIXEL]; 455 // pixel out buffer (16-bit per pixel) 456 uint8_t lcdidx = 0; 457 boolean 458 first = true; 459 460 uint8_t buffidx = sizeof(sdbuffer); // Current 461 position in sdbuffer 462 boolean goodBmp = false; // Set to true on 463 valid header parse 464 boolean flip = true; // BMP is stored bottom-to-top 465 466 int w, h, row, col; 467 uint8_t r, g, b; 468 uint32_t pos 469 = 0, startTime = millis(); 470 471 if((x >= my_lcd.width()) || (y >= my_lcd.height())) 472 return; 473 474 // Open requested file on SD card 475 if ((bmpFile = 476 SD.open(fileName)) == NULL) { 477 Serial.println("File Found??" ); 478 479 Serial.println( fileName); 480 return; 481 }else{ 482 Serial.println("File 483 Found" ); 484 } 485 486 487 if(_read16(bmpFile) == 0x4D42) 488 { // BMP signature 489 490 (void)_read32(bmpFile); // Read & ignore creator 491 bytes 492 Serial.print("File size: ");Serial.println( _read32(bmpFile) 493 ); 494 bmpImageoffset = _read32(bmpFile); // Start of image data 495 Serial.print(" 496 Header size: ");Serial.println( _read32(bmpFile) ); 497 498 // Read DIB 499 header 500 501 bmpWidth = _read32(bmpFile); 502 bmpHeight = _read32(bmpFile); 503 504 if(_read16(bmpFile) == 1) { // # planes -- must be '1' 505 bmpDepth 506 = _read16(bmpFile); // bits per pixel 507 508 if((bmpDepth == 24) && (_read32(bmpFile) 509 == 0)) { // 0 = uncompressed 510 511 goodBmp = true; // Supported BMP 512 format -- proceed! 513 514 // BMP rows are padded (if needed) to 4-byte 515 boundary 516 rowSize = (bmpWidth * 3 + 3) & ~3; 517 518 // 519 If bmpHeight is negative, image is in top-down order. 520 // This is 521 not canon but has been observed in the wild. 522 if(bmpHeight < 0) { 523 524 bmpHeight = -bmpHeight; 525 flip = false; 526 } 527 528 529 // Crop area to be loaded 530 w = bmpWidth; 531 h 532 = bmpHeight; 533 if((x+w-1) >= my_lcd.width()) w = my_lcd.width() - 534 x; 535 if((y+h-1) >= my_lcd.height()) h = my_lcd.height() - y; 536 537 538 // Set TFT address window to clipped image bounds 539 my_lcd.setAddrWindow(x, 540 y, x+w-1, y+h-1); 541 542 for (row=0; row<h; row++) { // For each scanline... 543 544 // Seek to start of scan line. It might seem labor- 545 // 546 intensive to be doing this on every line, but this 547 // method covers 548 a lot of gritty details like cropping 549 // and scanline padding. 550 Also, the seek only takes 551 // place if the file position actually 552 needs to change 553 // (avoids a lot of cluster math in SD library). 554 555 if(flip) // Bitmap is stored bottom-to-top order (normal BMP) 556 557 pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize; 558 else 559 // Bitmap is stored top-to-bottom 560 pos = bmpImageoffset + 561 row * rowSize; 562 if(bmpFile.position() != pos) { // Need seek? 563 564 bmpFile.seek(pos); 565 buffidx = sizeof(sdbuffer); 566 // Force buffer reload 567 } 568 569 for (col=0; col<w; 570 col++) { // For each column... 571 // Time to read more pixel data? 572 573 if (buffidx >= sizeof(sdbuffer)) { // Indeed 574 // 575 Push LCD buffer to the display first 576 577 if(lcdidx > 0) 578 { 579 my_lcd.pushColors(lcdbuffer, lcdidx, first); 580 lcdidx 581 = 0; 582 first = false; 583 } 584 585 586 bmpFile.read(sdbuffer, sizeof(sdbuffer)); 587 buffidx 588 = 0; // Set index to beginning 589 } 590 591 // Convert 592 pixel from BMP to TFT format 593 b = sdbuffer[buffidx++]; 594 g 595 = sdbuffer[buffidx++]; 596 r = sdbuffer[buffidx++]; 597 598 599 lcdbuffer[lcdidx++] = my_lcd.color565(r,g,b); 600 } 601 // end pixel 602 } // end scanline 603 604 if(lcdidx 605 > 0) { 606 my_lcd.pushColors(lcdbuffer, lcdidx, first); 607 } 608 609 Serial.print("Loaded in: ");Serial.println( millis() - startTime); 610 611 } // end goodBmp 612 } 613 } 614 615 bmpFile.close(); 616 617 if(!goodBmp) Serial.println("BMP format not recognized."); 618 } 619 620 621
Downloadable files
Schematics of all project
Schematics of all project
Schematics of all project
Schematics of all project
Schematics
Schematics
Comments
Only logged in users can leave comments
roger_marin
0 Followers
•0 Projects
Table of contents
Intro
10
0