Laptop Keyboard Typing model TFT LCD Project
Created Keyboard layout in TFT LCD Shield & also you can use as typewriter
Components and supplies
1
Arduino UNO
1
TFT LCD, 2.4 "
Apps and platforms
1
Arduino IDE
Project description
Code
TFT LCD Keyboard typing model
c_cpp
You can type the words by touching the Touch screen of TFT LCD
1//This project is done by Teach Me Something 2 3#include <Adafruit_GFX.h> // Core graphics library 4#include <MCUFRIEND_kbv.h> 5#include "TouchScreen.h" 6MCUFRIEND_kbv tft; 7/*______End of Libraries_______*/ 8 9/*______Define LCD pins (I have asigned the default values)_______*/ 10#define YP A1 // must be an analog pin, use "An" notation! 11#define XM A2 // must be an analog pin, use "An" notation! 12#define YM 7 // can be a digital pin 13#define XP 6 // can be a digital pin 14#define LCD_CS A3 15#define LCD_CD A2 16#define LCD_WR A1 17#define LCD_RD A0 18#define LCD_RESET A4 19/*_______End of defanitions______*/ 20 21/*______Assign names to colors and pressure_______*/ 22#define BLACK 0x0000 23#define BROWN 0x7980 24#define RED 0xF800 25#define ORANGE 0xFBE0 26#define YELLOW 0xFFE0 27#define GREEN 0x07E0 28#define BLUE 0x001F 29#define VIOLET 0xA81F 30#define GREY 0x7BEF 31#define WHITE 0xFFFF 32#define CYAN 0x07FF 33#define MAGENTA 0xF81F 34#define LGREEN 0xAFE0 35 36 37#define MINPRESSURE 10 38#define MAXPRESSURE 1200 39/*_______Assigned______*/ 40 41/*____Calibrate TFT LCD_____*/ 42#define TS_MINX 910 // left 43#define TS_MINY 760 // t09 44#define TS_MAXX 180 // RT 45#define TS_MAXY 135 // Bot 46/*______End of Calibration______*/ 47 48TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //300 is the sensitivity 49//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Start communication with LCD 50int i=0; 51int j=0; 52int a=0; 53int b=0; 54int c=0; 55boolean Caps=false; 56String symbol[3][10] = { 57 { "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P" }, 58 { "A", "S", "D", "F", "G", "H", "J", "K", "L", ";" }, 59 { "Caps", "Z", "X", "C", "V", "B", "N", "M", ".", "<" } 60}; 61 int X,Y; 62 63void setup() { 64 Serial.begin(9600); //Use serial monitor for debugging 65 tft.reset(); //Always reset at start 66 tft.begin(0x9341); // My LCD uses LIL9341 Interface driver IC 67 tft.setRotation(1); // I just roated so that the power jack faces up - optional 68 tft.invertDisplay(1); 69 IntroScreen(); 70 draw_BoxNButtons(); 71 tft.setCursor(0,0); 72 73 74} 75 76void loop() { 77TSPoint p = waitTouch(); 78tft.setCursor (a,b); 79tft.setTextSize (2); 80tft.setTextColor(WHITE); 81DetectButtons(); 82delay(300); 83} 84 85 86TSPoint waitTouch() { 87 88 TSPoint p; 89 do { 90 p = ts.getPoint(); 91 pinMode(XM, OUTPUT); 92 pinMode(YP, OUTPUT); 93 } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE)); 94 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320); 95 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240); 96 X = p.y; Y = p.x; 97 Serial.print(X); Serial.print(','); Serial.println(Y);// + " " + Y); 98 return p; 99} 100 101 102void DetectButtons() 103{ 104 105 if ( 20<X && X<45 && Y<38) //Detecting Buttons on Column 1 106 { Caps = !Caps; 107 Serial.print(Caps); 108 a=a-12; 109 if(Caps){ 110 tft.setCursor (275, 90); 111 tft.setTextSize (1); 112 tft.setTextColor(WHITE); 113 tft.println("CAPS ON"); 114 } 115 else 116 tft.fillRect (275,90,50,10,BLACK); 117 delay(500); 118 } 119 120 else if ( 20<X && X<45 && 38<Y && Y<70) 121 { 122 if (Caps) 123 tft.print("Z"); 124 else 125 tft.print("z"); 126 } 127 else if ( 20<X && X<45 && 70<Y && Y<105) 128 { 129 if (Caps) 130 tft.print("X"); 131 else 132 tft.print("x"); 133 } 134 135 else if ( 20<X && X<45 && 105<Y && Y<143) 136 { 137 if (Caps) 138 tft.print("C"); 139 else 140 tft.print("c"); 141 } 142 143 else if ( 20<X && X<45 && 143<Y && Y<180) 144 { 145 if (Caps) 146 tft.print("V"); 147 else 148 tft.print("v"); 149 } 150 151 else if ( 20<X && X<45 && 180<Y && Y<215) 152 { 153 if (Caps) 154 tft.print("B"); 155 else 156 tft.print("b"); 157 } 158 159 else if ( 17<X && X<45 && 215<Y && Y<250) 160 { 161 if (Caps) 162 tft.print("N"); 163 else 164 tft.print("n"); 165 } 166 167 else if ( 10<X && X<45 && 250<Y && Y<285) 168 { 169 if (Caps) 170 tft.print("M"); 171 else 172 tft.print("m"); 173 } 174 175 else if ( 10<X && X<45 && 285<Y && Y<320) 176 { 177 if (Caps) 178 tft.print("."); 179 else 180 tft.print("."); 181 } 182 183 else if ( 3<X && X<40 && 320<Y ) 184 { 185 a=a-12; 186 tft.fillRect(a,b,12,20,BLACK); 187 a=a-12; 188 Serial.print("a="); 189 Serial.println(a); 190 191 } 192 193 else if ( 45<X && X<75 && 0<Y && Y<38) 194 { 195 if (Caps) 196 tft.print("A"); 197 else 198 tft.print("a"); 199 } 200 else if ( 45<X && X<75 && 38<Y && Y<70) 201 { 202 if (Caps) 203 tft.print("S"); 204 else 205 tft.print("s"); 206 } 207 else if ( 45<X && X<75 && 64<Y && Y<105) 208 { 209 if (Caps) 210 tft.print("D"); 211 else 212 tft.print("d"); 213 } 214 else if ( 45<X && X<75 && 96<Y && Y<143) 215 { 216 if (Caps) 217 tft.print("F"); 218 else 219 tft.print("f"); 220 } 221 else if ( 45<X && X<75 && 128<Y && Y<180) 222 { 223 if (Caps) 224 tft.print("G"); 225 else 226 tft.print("g"); 227 } 228 else if ( 45<X && X<75 && 160<Y && Y<215) 229 { 230 if (Caps) 231 tft.print("H"); 232 else 233 tft.print("h"); 234 } 235 else if ( 45<X && X<75 && 192<Y && Y<250) 236 { 237 if (Caps) 238 tft.print("J"); 239 else 240 tft.print("j"); 241 } 242 else if ( 45<X && X<75 && 224<Y && Y<285) 243 { 244 if (Caps) 245 tft.print("K"); 246 else 247 tft.print("k"); 248 } 249 else if ( 45<X && X<75 && 256<Y && Y<320) 250 { 251 if (Caps) 252 tft.print("L"); 253 else 254 tft.print("l"); 255 } 256 else if ( 45<X && X<75 && 320<Y) 257 { 258 a=-12; 259 b=b+20; 260 } 261 262 263 else if ( 75<X && X<100 && 0<Y && Y<38) 264 { 265 if (Caps) 266 tft.print("Q"); 267 else 268 tft.print("q"); 269 } 270 else if ( 75<X && X<100 && 32<Y && Y<70) 271 { 272 if (Caps) 273 tft.print("W"); 274 else 275 tft.print("w"); 276 } 277 else if ( 75<X && X<100 && 64<Y && Y<105) 278 { 279 if (Caps) 280 tft.print("E"); 281 else 282 tft.print("e"); 283 } 284 else if ( 75<X && X<100 && 96<Y && Y<143) 285 { 286 if (Caps) 287 tft.print("R"); 288 else 289 tft.print("r"); 290 } 291 else if ( 75<X && X<100 && 128<Y && Y<180) 292 { 293 if (Caps) 294 tft.print("T"); 295 else 296 tft.print("t"); 297 } 298 else if ( 75<X && X<100 && 160<Y && Y<215) 299 { 300 if (Caps) 301 tft.print("Y"); 302 else 303 tft.print("y"); 304 } 305 else if ( 75<X && X<100 && 192<Y && Y<250) 306 { 307 if (Caps) 308 tft.print("U"); 309 else 310 tft.print("u"); 311 } 312 else if ( 75<X && X<100 && 224<Y && Y<285) 313 { 314 if (Caps) 315 tft.print("I"); 316 else 317 tft.print("i"); 318 } 319 else if ( 75<X && X<100 && 256<Y && Y<320) 320 { 321 if (Caps) 322 tft.print("O"); 323 else 324 tft.print("o"); 325 } 326 else if ( 75<X && X<100 && 320<Y ) 327 { 328 if (Caps) 329 tft.print("P"); 330 else 331 tft.print("p"); 332 } 333 else if ( X<8 && 250<Y && Y<350) // Reset button 334 { 335 tft.fillRect(0,0,320,100,BLACK); 336 a=-12; 337 b=0; 338 } 339 340 a=a+12; 341 if(a>310) 342 {b=b+20; 343 a=0; 344 } 345 346 347} 348 349 350 351 352 353void IntroScreen() 354{tft.fillScreen(BLACK); 355 tft.setCursor (20, 30); 356 tft.setTextSize (3); 357 tft.setTextColor(RED); 358 tft.println("ARDUINO Project"); 359 tft.setTextColor(YELLOW); 360 tft.setCursor (30, 110); 361 tft.setTextSize (2); 362 tft.println("Laptop Keyboard Typing"); 363 tft.setTextSize (2); 364 tft.setCursor (55, 180); 365 tft.setTextColor(BLUE); 366 tft.println("Teach Me Something"); 367 delay(4000); 368 369} 370 371void draw_BoxNButtons() 372{ tft.fillScreen(BLACK); 373 // tft.fillRect(0,135,320,105,WHITE); 374 tft.setTextSize (3); 375 tft.setTextColor(RED); 376 for( j=0; j<3;j++) 377 { 378 for ( i=0; i<10; i++) 379 { 380 tft.fillRoundRect((i*32)+1, j*35+101, 31, 34, 3,YELLOW); 381 tft.setCursor (i*32+9,j*35+107 ); 382 tft.print(symbol[j][i]); 383 } 384 } 385 tft.fillRoundRect(1,171, 31, 34, 3,CYAN); 386 tft.setTextColor(BLACK); 387 tft.setTextSize (1); 388 tft.setCursor (5,185 ); 389 tft.print("Caps"); 390 tft.fillRoundRect(289,171, 31, 34, 3,0Xfbef); 391 tft.setTextColor(BLACK); 392 tft.setTextSize (2); 393 tft.setCursor (290,182 ); 394 tft.print("<-"); 395 396 tft.fillRoundRect(289,136, 31, 34, 3,CYAN); 397 tft.setTextColor(RED); 398 tft.setTextSize (1); 399 tft.setCursor (290,150 ); 400 tft.print("Enter"); 401 402 tft.fillRoundRect(1,206, 223, 34, 3,VIOLET); 403 tft.setTextColor(WHITE); 404 tft.setTextSize (2); 405 tft.setCursor (55,215 ); 406 tft.print("Space Bar"); 407 408 409 tft.fillRoundRect(225,206, 95, 34, 3,WHITE); 410 tft.setTextColor(VIOLET); 411 tft.setTextSize (2); 412 tft.setCursor (247,217 ); 413 tft.print("RESET"); 414 415 while( c<5) 416 { 417 tft.setCursor(55,25); 418 tft.setTextColor(WHITE); 419 tft.setTextSize (2); 420 tft.print("Teach Me Something"); 421 tft.setCursor(100,60); 422 tft.print("Type Here"); 423 delay(500); 424 tft.fillRect(0,0,320,100,BLACK); 425 delay(500); 426 c++; 427 } 428 429}
TFT LCD Keyboard typing model
c_cpp
You can type the words by touching the Touch screen of TFT LCD
1//This project is done by Teach Me Something 2 3#include <Adafruit_GFX.h> // Core graphics library 4#include <MCUFRIEND_kbv.h> 5#include "TouchScreen.h" 6MCUFRIEND_kbv tft; 7/*______End of Libraries_______*/ 8 9/*______Define LCD pins (I have asigned the default values)_______*/ 10#define YP A1 // must be an analog pin, use "An" notation! 11#define XM A2 // must be an analog pin, use "An" notation! 12#define YM 7 // can be a digital pin 13#define XP 6 // can be a digital pin 14#define LCD_CS A3 15#define LCD_CD A2 16#define LCD_WR A1 17#define LCD_RD A0 18#define LCD_RESET A4 19/*_______End of defanitions______*/ 20 21/*______Assign names to colors and pressure_______*/ 22#define BLACK 0x0000 23#define BROWN 0x7980 24#define RED 0xF800 25#define ORANGE 0xFBE0 26#define YELLOW 0xFFE0 27#define GREEN 0x07E0 28#define BLUE 0x001F 29#define VIOLET 0xA81F 30#define GREY 0x7BEF 31#define WHITE 0xFFFF 32#define CYAN 0x07FF 33#define MAGENTA 0xF81F 34#define LGREEN 0xAFE0 35 36 37#define MINPRESSURE 10 38#define MAXPRESSURE 1200 39/*_______Assigned______*/ 40 41/*____Calibrate TFT LCD_____*/ 42#define TS_MINX 910 // left 43#define TS_MINY 760 // t09 44#define TS_MAXX 180 // RT 45#define TS_MAXY 135 // Bot 46/*______End of Calibration______*/ 47 48TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //300 is the sensitivity 49//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Start communication with LCD 50int i=0; 51int j=0; 52int a=0; 53int b=0; 54int c=0; 55boolean Caps=false; 56String symbol[3][10] = { 57 { "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P" }, 58 { "A", "S", "D", "F", "G", "H", "J", "K", "L", ";" }, 59 { "Caps", "Z", "X", "C", "V", "B", "N", "M", ".", "<" } 60}; 61 int X,Y; 62 63void setup() { 64 Serial.begin(9600); //Use serial monitor for debugging 65 tft.reset(); //Always reset at start 66 tft.begin(0x9341); // My LCD uses LIL9341 Interface driver IC 67 tft.setRotation(1); // I just roated so that the power jack faces up - optional 68 tft.invertDisplay(1); 69 IntroScreen(); 70 draw_BoxNButtons(); 71 tft.setCursor(0,0); 72 73 74} 75 76void loop() { 77TSPoint p = waitTouch(); 78tft.setCursor (a,b); 79tft.setTextSize (2); 80tft.setTextColor(WHITE); 81DetectButtons(); 82delay(300); 83} 84 85 86TSPoint waitTouch() { 87 88 TSPoint p; 89 do { 90 p = ts.getPoint(); 91 pinMode(XM, OUTPUT); 92 pinMode(YP, OUTPUT); 93 } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE)); 94 p.x = map(p.x, TS_MINX, TS_MAXX, 0, 320); 95 p.y = map(p.y, TS_MINY, TS_MAXY, 0, 240); 96 X = p.y; Y = p.x; 97 Serial.print(X); Serial.print(','); Serial.println(Y);// + " " + Y); 98 return p; 99} 100 101 102void DetectButtons() 103{ 104 105 if ( 20<X && X<45 && Y<38) //Detecting Buttons on Column 1 106 { Caps = !Caps; 107 Serial.print(Caps); 108 a=a-12; 109 if(Caps){ 110 tft.setCursor (275, 90); 111 tft.setTextSize (1); 112 tft.setTextColor(WHITE); 113 tft.println("CAPS ON"); 114 } 115 else 116 tft.fillRect (275,90,50,10,BLACK); 117 delay(500); 118 } 119 120 else if ( 20<X && X<45 && 38<Y && Y<70) 121 { 122 if (Caps) 123 tft.print("Z"); 124 else 125 tft.print("z"); 126 } 127 else if ( 20<X && X<45 && 70<Y && Y<105) 128 { 129 if (Caps) 130 tft.print("X"); 131 else 132 tft.print("x"); 133 } 134 135 else if ( 20<X && X<45 && 105<Y && Y<143) 136 { 137 if (Caps) 138 tft.print("C"); 139 else 140 tft.print("c"); 141 } 142 143 else if ( 20<X && X<45 && 143<Y && Y<180) 144 { 145 if (Caps) 146 tft.print("V"); 147 else 148 tft.print("v"); 149 } 150 151 else if ( 20<X && X<45 && 180<Y && Y<215) 152 { 153 if (Caps) 154 tft.print("B"); 155 else 156 tft.print("b"); 157 } 158 159 else if ( 17<X && X<45 && 215<Y && Y<250) 160 { 161 if (Caps) 162 tft.print("N"); 163 else 164 tft.print("n"); 165 } 166 167 else if ( 10<X && X<45 && 250<Y && Y<285) 168 { 169 if (Caps) 170 tft.print("M"); 171 else 172 tft.print("m"); 173 } 174 175 else if ( 10<X && X<45 && 285<Y && Y<320) 176 { 177 if (Caps) 178 tft.print("."); 179 else 180 tft.print("."); 181 } 182 183 else if ( 3<X && X<40 && 320<Y ) 184 { 185 a=a-12; 186 tft.fillRect(a,b,12,20,BLACK); 187 a=a-12; 188 Serial.print("a="); 189 Serial.println(a); 190 191 } 192 193 else if ( 45<X && X<75 && 0<Y && Y<38) 194 { 195 if (Caps) 196 tft.print("A"); 197 else 198 tft.print("a"); 199 } 200 else if ( 45<X && X<75 && 38<Y && Y<70) 201 { 202 if (Caps) 203 tft.print("S"); 204 else 205 tft.print("s"); 206 } 207 else if ( 45<X && X<75 && 64<Y && Y<105) 208 { 209 if (Caps) 210 tft.print("D"); 211 else 212 tft.print("d"); 213 } 214 else if ( 45<X && X<75 && 96<Y && Y<143) 215 { 216 if (Caps) 217 tft.print("F"); 218 else 219 tft.print("f"); 220 } 221 else if ( 45<X && X<75 && 128<Y && Y<180) 222 { 223 if (Caps) 224 tft.print("G"); 225 else 226 tft.print("g"); 227 } 228 else if ( 45<X && X<75 && 160<Y && Y<215) 229 { 230 if (Caps) 231 tft.print("H"); 232 else 233 tft.print("h"); 234 } 235 else if ( 45<X && X<75 && 192<Y && Y<250) 236 { 237 if (Caps) 238 tft.print("J"); 239 else 240 tft.print("j"); 241 } 242 else if ( 45<X && X<75 && 224<Y && Y<285) 243 { 244 if (Caps) 245 tft.print("K"); 246 else 247 tft.print("k"); 248 } 249 else if ( 45<X && X<75 && 256<Y && Y<320) 250 { 251 if (Caps) 252 tft.print("L"); 253 else 254 tft.print("l"); 255 } 256 else if ( 45<X && X<75 && 320<Y) 257 { 258 a=-12; 259 b=b+20; 260 } 261 262 263 else if ( 75<X && X<100 && 0<Y && Y<38) 264 { 265 if (Caps) 266 tft.print("Q"); 267 else 268 tft.print("q"); 269 } 270 else if ( 75<X && X<100 && 32<Y && Y<70) 271 { 272 if (Caps) 273 tft.print("W"); 274 else 275 tft.print("w"); 276 } 277 else if ( 75<X && X<100 && 64<Y && Y<105) 278 { 279 if (Caps) 280 tft.print("E"); 281 else 282 tft.print("e"); 283 } 284 else if ( 75<X && X<100 && 96<Y && Y<143) 285 { 286 if (Caps) 287 tft.print("R"); 288 else 289 tft.print("r"); 290 } 291 else if ( 75<X && X<100 && 128<Y && Y<180) 292 { 293 if (Caps) 294 tft.print("T"); 295 else 296 tft.print("t"); 297 } 298 else if ( 75<X && X<100 && 160<Y && Y<215) 299 { 300 if (Caps) 301 tft.print("Y"); 302 else 303 tft.print("y"); 304 } 305 else if ( 75<X && X<100 && 192<Y && Y<250) 306 { 307 if (Caps) 308 tft.print("U"); 309 else 310 tft.print("u"); 311 } 312 else if ( 75<X && X<100 && 224<Y && Y<285) 313 { 314 if (Caps) 315 tft.print("I"); 316 else 317 tft.print("i"); 318 } 319 else if ( 75<X && X<100 && 256<Y && Y<320) 320 { 321 if (Caps) 322 tft.print("O"); 323 else 324 tft.print("o"); 325 } 326 else if ( 75<X && X<100 && 320<Y ) 327 { 328 if (Caps) 329 tft.print("P"); 330 else 331 tft.print("p"); 332 } 333 else if ( X<8 && 250<Y && Y<350) // Reset button 334 { 335 tft.fillRect(0,0,320,100,BLACK); 336 a=-12; 337 b=0; 338 } 339 340 a=a+12; 341 if(a>310) 342 {b=b+20; 343 a=0; 344 } 345 346 347} 348 349 350 351 352 353void IntroScreen() 354{tft.fillScreen(BLACK); 355 tft.setCursor (20, 30); 356 tft.setTextSize (3); 357 tft.setTextColor(RED); 358 tft.println("ARDUINO Project"); 359 tft.setTextColor(YELLOW); 360 tft.setCursor (30, 110); 361 tft.setTextSize (2); 362 tft.println("Laptop Keyboard Typing"); 363 tft.setTextSize (2); 364 tft.setCursor (55, 180); 365 tft.setTextColor(BLUE); 366 tft.println("Teach Me Something"); 367 delay(4000); 368 369} 370 371void draw_BoxNButtons() 372{ tft.fillScreen(BLACK); 373 // tft.fillRect(0,135,320,105,WHITE); 374 tft.setTextSize (3); 375 tft.setTextColor(RED); 376 for( j=0; j<3;j++) 377 { 378 for ( i=0; i<10; i++) 379 { 380 tft.fillRoundRect((i*32)+1, j*35+101, 31, 34, 3,YELLOW); 381 tft.setCursor (i*32+9,j*35+107 ); 382 tft.print(symbol[j][i]); 383 } 384 } 385 tft.fillRoundRect(1,171, 31, 34, 3,CYAN); 386 tft.setTextColor(BLACK); 387 tft.setTextSize (1); 388 tft.setCursor (5,185 ); 389 tft.print("Caps"); 390 tft.fillRoundRect(289,171, 31, 34, 3,0Xfbef); 391 tft.setTextColor(BLACK); 392 tft.setTextSize (2); 393 tft.setCursor (290,182 ); 394 tft.print("<-"); 395 396 tft.fillRoundRect(289,136, 31, 34, 3,CYAN); 397 tft.setTextColor(RED); 398 tft.setTextSize (1); 399 tft.setCursor (290,150 ); 400 tft.print("Enter"); 401 402 tft.fillRoundRect(1,206, 223, 34, 3,VIOLET); 403 tft.setTextColor(WHITE); 404 tft.setTextSize (2); 405 tft.setCursor (55,215 ); 406 tft.print("Space Bar"); 407 408 409 tft.fillRoundRect(225,206, 95, 34, 3,WHITE); 410 tft.setTextColor(VIOLET); 411 tft.setTextSize (2); 412 tft.setCursor (247,217 ); 413 tft.print("RESET"); 414 415 while( c<5) 416 { 417 tft.setCursor(55,25); 418 tft.setTextColor(WHITE); 419 tft.setTextSize (2); 420 tft.print("Teach Me Something"); 421 tft.setCursor(100,60); 422 tft.print("Type Here"); 423 delay(500); 424 tft.fillRect(0,0,320,100,BLACK); 425 delay(500); 426 c++; 427 } 428 429}
Downloadable files
Pin details of 2.4 inch TFT LCD Shield
Pin details of 2.4 inch TFT LCD Shield

Comments
Only logged in users can leave comments