Components and supplies
2.4 inch TFT LCD Shield touch screen
Arduino UNO
USB-A to B Cable
Apps and platforms
Arduino IDE
Project description
Code
Resistor value calculator by TFT LCD Project
c_cpp
Use this calculator to find out the ohm value and tolerance based on resistor color codes.
1//This project is done by Teach Me Something 2#include <Adafruit_GFX.h> // Core graphics library 3#include <MCUFRIEND_kbv.h> 4#include "TouchScreen.h" 5MCUFRIEND_kbv tft; 6/*______End of Libraries_______*/ 7 8/*______Define LCD pins (I have asigned the default values)_______*/ 9#define YP A1 // must be an analog pin, use "An" notation! 10#define XM A2 // must be an analog pin, use "An" notation! 11#define YM 7 // can be a digital pin 12#define XP 6 // can be a digital pin 13#define LCD_CS A3 14#define LCD_CD A2 15#define LCD_WR A1 16#define LCD_RD A0 17#define LCD_RESET A4 18/*_______End of defanitions______*/ 19 20/*______Assign names to colors and pressure_______*/ 21#define BLACK 0x0000 22#define BROWN 0x7980 23#define RED 0xF800 24#define ORANGE 0xFBE0 25#define YELLOW 0xFFE0 26#define GREEN 0x07E0 27#define BLUE 0x001F 28#define VIOLET 0xA81F 29#define GREY 0x7BEF 30#define WHITE 0xFFFF 31#define CYAN 0x07FF 32#define MAGENTA 0xF81F 33 34#define MINPRESSURE 10 35#define MAXPRESSURE 1200 36/*_______Assigned______*/ 37 38/*____Calibrate TFT LCD_____*/ 39#define TS_MINX 910 // left 40#define TS_MINY 760 // t09 41#define TS_MAXX 180 // RT 42#define TS_MAXY 135 // Bot 43/*______End of Calibration______*/ 44 45TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //300 is the sensitivity 46//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Start communication with LCD 47 48String symbol[3][4] = { 49 { "0", "1", "2", "3" }, 50 { "4", "5", "6", "7" }, 51 { "8", "9", "C", "K" } 52}; 53String colors[1][10]= 54 { "Black","Brown","Red","Orange","Yellow","Green","Blue","Violet","Grey","White"}; 55 int X,Y; 56 int ring,ring1,ring2,ring3,ring4=0; 57 long Number1; 58 char C; 59 char K; 60 long resistance=0; 61void setup() { 62 Serial.begin(9600); //Use serial monitor for debugging 63 tft.reset(); //Always reset at start 64 tft.begin(0x9341); // My LCD uses LIL9341 Interface driver IC 65 tft.setRotation(2); // I just roated so that the power jack faces up - optional 66 tft.invertDisplay(1); 67 IntroScreen(); 68 draw_BoxNButtons(); 69} 70 71void loop() { 72 73TSPoint p = waitTouch(); 74X = p.y; Y = p.x; 75Serial.print(X); Serial.print(','); Serial.println(Y);// + " " + Y); 76 77 78DetectButtons(); 79 80Ring(); 81//if(ring>3) 82//calculation(); 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 return p; 97} 98 99 100void DetectButtons() 101{ 102 103 if ( X>135) //Detecting Buttons on Column 1 104 { 105 if (Y>0 && Y<60) //If Button 9 is pressed 106 {Serial.println ("Button 8"); 107 Number1=8; 108 } 109 110 if (Y>60 && Y<120) //If Button 5 is pressed 111 {Serial.println ("Button 4"); 112 Number1=4; 113 } 114 115 if (Y>120 && Y<180) //If Button 1 is pressed 116 {Serial.println ("Button 0"); 117 118 Number1=0; 119 } 120 121 122 } 123 124 if (X<135 && X>90) //Detecting Buttons on Column 2 125 { 126 if (Y>0 && Y<60) 127 {Serial.println ("Button 9"); //Button 10 is Pressed 128 129 Number1=9; 130 } 131 132 if (Y>60 && Y<120) 133 {Serial.println ("Button 5"); 134 Number1=5; 135 } 136 137 if (Y>120 && Y<180) 138 {Serial.println ("Button 1"); 139 Number1=1; 140 } 141 142 143 } 144 145 if (X<90 && X>40) //Detecting Buttons on Column 3 146 { 147 if (Y>0 && Y<60) 148 {Serial.println ("Button C"); 149 150 ring=0; 151 ring1=0; 152 ring2=0; 153 ring3=0; 154 ring4=0; 155 156 // IntroScreen(); 157 draw_BoxNButtons(); 158 resistance=0; 159 Number1=0; 160 161// finalvalue1=0; 162 delay(500); 163 164 return; 165 166 } 167 168 if (Y>60 && Y<120) 169 {Serial.println ("Button 6"); 170 Number1=6; 171 } 172 173 if (Y>120 && Y<180) 174 {Serial.println ("Button 2"); 175 Number1=2; 176 } 177 178 } 179 180 if (X<48) //Detecting Buttons on Column 4 181{ 182 if (Y>0 && Y<60) 183 {Serial.println ("Button K"); 184 185 if(ring>3) 186calculation(); 187else 188 draw_BoxNButtons(); 189 190 ring=-1; 191 ring1=0; 192 ring2=0; 193 ring3=0; 194 ring4=0; 195 delay(700); 196 } 197 198 if (Y>60 && Y<120) 199 {Serial.println ("Button 7"); 200 Number1=7; 201 } 202 203 if (Y>120 && Y<180) 204 {Serial.println ("Button 3"); 205 Number1=3; 206 } 207 208 209 } 210 if(!(ring>3 || ring==-1)) 211{ 212 tft.setCursor(55, 28+(20*ring)); 213 tft.setTextColor(RED); 214 tft.setTextSize(2); 215 tft.println(colors[0][Number1]); 216 delay(300); 217 ring++; 218} 219else 220ring++; 221 222} 223 224 225 226 227 228void IntroScreen() 229{tft.fillScreen(BLACK); 230 tft.setCursor (55, 50); 231 tft.setTextSize (3); 232 tft.setTextColor(RED); 233 tft.println("ARDUINO"); 234 tft.setTextColor(YELLOW); 235 tft.setCursor (60, 140); 236 tft.setTextSize (2); 237 tft.println("Resistor "); 238 tft.setCursor (10, 170); 239 tft.println("Color Coding Game"); 240 tft.setCursor (10, 230); 241 tft.setTextColor(BLUE); 242 tft.println("Teach Me Something"); 243 delay(4000); 244 245} 246 247void draw_BoxNButtons() 248{ 249 //Draw the Result Box 250 tft.fillRect(0, 0, 240, 140,BLUE); 251 tft.fillRect(20, 25, 20, 85,WHITE); 252 for(int a=0; a<3;a++) 253 {tft.drawLine(29+a,25,29+a,15,WHITE); 254 tft.drawLine(29+a,80,29+a,120,WHITE); 255 256 } 257 tft.fillRect(20,35,20,3,BLACK); 258 tft.fillRect(20,55,20,3,BLACK); 259 260 tft.fillRect(20,75,20,3,BLACK); 261 tft.fillRect(20,100,20,3,BLACK); 262 263 //Draw First Column 264 tft.fillRect (0,260,60,60,GREY); 265 tft.fillRect (0,200,60,60,YELLOW); 266 tft.fillRect (0,140,60,60,BLACK); 267 268 //Draw Second Column 269 tft.fillRect (60,260,60,60,WHITE); 270 tft.fillRect (60,200,60,60,GREEN); 271 tft.fillRect (60,140,60,60,BROWN); 272 273 //Draw Third Column 274 tft.fillRect (120,260,60,60,BLACK); 275 tft.fillRect (120,200,60,60,BLUE); 276 tft.fillRect (120,140,60,60,RED); 277 278 //Draw 4th Column 279 tft.fillRect (180,260,60,60,BLACK); 280 tft.fillRect (180,200,60,60,MAGENTA); 281 tft.fillRect (180,140,60,60,ORANGE); 282 283 284 //Draw Horizontal Lines 285 for (int h=140; h<=320; h+=60) 286 tft.drawFastHLine(0, h, 240, WHITE); 287 288 //Draw Vertical Lines 289 for (int v=0; v<=240; v+=60) 290 tft.drawFastVLine(v, 140, 240, WHITE); 291 292 //Display keypad lables 293 for (int j=0;j<3;j++) { 294 for (int i=0;i<4;i++) { 295 tft.setCursor(22 + (60*i), 100 + (60*(j+1))); 296 tft.setTextSize(3); 297 tft.setTextColor(WHITE); 298 tft.println(symbol[j][i]); 299 300 } 301 302 303 } 304 305 tft.setTextSize(3); 306 tft.setTextColor(BLACK); 307 tft.setCursor(22 , 220); 308 tft.println("4"); 309 tft.setCursor(82 , 280); 310 tft.println("9"); 311 tft.setTextColor(RED); 312 tft.setCursor(22 , 280); 313 tft.println("8"); 314 tft.fillRect (181,261,60,60,BLACK); 315 316 tft.setTextSize(3); 317 tft.setCursor(195 , 280); 318 tft.println("OK"); 319} 320 321void Ring() 322{ 323if(ring==1) 324ring1=Number1; 325if(ring==2) 326ring2=Number1; 327if(ring==3) 328ring3=Number1; 329if(ring==4) 330ring4=Number1; 331} 332 333 334void calculation() 335{ 336 337 long test; 338 float finalvalue1; 339 int mega=0; 340 341 if(ring3==0) 342 test=1; 343 if(ring3==1) 344 test=10; 345 if(ring3==2) 346 test=100; 347 if(ring3==3) 348 test=1000; 349 if(ring3==4) 350 test=10000; 351 if(ring3==5) 352 {test=1; 353 mega=1;}; 354 if(ring3==6) 355 {test=10; 356 mega=1;} 357 if(ring3==7) 358 {test=100; 359 mega=1;} 360 if(ring3==8) 361 {test=1000; 362 mega=1;} 363 if(ring3==9) 364 {test=10000; 365 mega=1;} 366resistance= (ring1*10+ring2)*test;teac 367Serial.println(resistance); 368Serial.println(ring1); 369Serial.println(ring2); 370Serial.println(ring3); 371 372 373 tft.setTextSize(3); 374tft.setTextColor(WHITE); 375tft.setCursor(145 , 20); 376if(resistance<1000 && mega==0) 377{tft.println(resistance); 378 tft.setCursor(145 , 50); 379tft.print("Ohms"); 380} 381else if(resistance>999 && mega==0) 382{ 383 384 finalvalue1=(float)resistance/1000; 385 tft.print(finalvalue1); 386 tft.setCursor(145 , 60); 387 tft.print("K.Ohm"); 388} 389else 390{ 391 392 finalvalue1=(float)resistance/10; 393 tft.print(finalvalue1); 394 tft.setCursor(145 , 60); 395 tft.print("M.Ohm"); 396} 397 ring=0; 398}
Resistor value calculator by TFT LCD Project
c_cpp
Use this calculator to find out the ohm value and tolerance based on resistor color codes.
1//This project is done by Teach Me Something 2#include <Adafruit_GFX.h> // Core graphics library 3#include <MCUFRIEND_kbv.h> 4#include "TouchScreen.h" 5MCUFRIEND_kbv tft; 6/*______End of Libraries_______*/ 7 8/*______Define LCD pins (I have asigned the default values)_______*/ 9#define YP A1 // must be an analog pin, use "An" notation! 10#define XM A2 // must be an analog pin, use "An" notation! 11#define YM 7 // can be a digital pin 12#define XP 6 // can be a digital pin 13#define LCD_CS A3 14#define LCD_CD A2 15#define LCD_WR A1 16#define LCD_RD A0 17#define LCD_RESET A4 18/*_______End of defanitions______*/ 19 20/*______Assign names to colors and pressure_______*/ 21#define BLACK 0x0000 22#define BROWN 0x7980 23#define RED 0xF800 24#define ORANGE 0xFBE0 25#define YELLOW 0xFFE0 26#define GREEN 0x07E0 27#define BLUE 0x001F 28#define VIOLET 0xA81F 29#define GREY 0x7BEF 30#define WHITE 0xFFFF 31#define CYAN 0x07FF 32#define MAGENTA 0xF81F 33 34#define MINPRESSURE 10 35#define MAXPRESSURE 1200 36/*_______Assigned______*/ 37 38/*____Calibrate TFT LCD_____*/ 39#define TS_MINX 910 // left 40#define TS_MINY 760 // t09 41#define TS_MAXX 180 // RT 42#define TS_MAXY 135 // Bot 43/*______End of Calibration______*/ 44 45TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //300 is the sensitivity 46//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //Start communication with LCD 47 48String symbol[3][4] = { 49 { "0", "1", "2", "3" }, 50 { "4", "5", "6", "7" }, 51 { "8", "9", "C", "K" } 52}; 53String colors[1][10]= 54 { "Black","Brown","Red","Orange","Yellow","Green","Blue","Violet","Grey","White"}; 55 int X,Y; 56 int ring,ring1,ring2,ring3,ring4=0; 57 long Number1; 58 char C; 59 char K; 60 long resistance=0; 61void setup() { 62 Serial.begin(9600); //Use serial monitor for debugging 63 tft.reset(); //Always reset at start 64 tft.begin(0x9341); // My LCD uses LIL9341 Interface driver IC 65 tft.setRotation(2); // I just roated so that the power jack faces up - optional 66 tft.invertDisplay(1); 67 IntroScreen(); 68 draw_BoxNButtons(); 69} 70 71void loop() { 72 73TSPoint p = waitTouch(); 74X = p.y; Y = p.x; 75Serial.print(X); Serial.print(','); Serial.println(Y);// + " " + Y); 76 77 78DetectButtons(); 79 80Ring(); 81//if(ring>3) 82//calculation(); 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 return p; 97} 98 99 100void DetectButtons() 101{ 102 103 if ( X>135) //Detecting Buttons on Column 1 104 { 105 if (Y>0 && Y<60) //If Button 9 is pressed 106 {Serial.println ("Button 8"); 107 Number1=8; 108 } 109 110 if (Y>60 && Y<120) //If Button 5 is pressed 111 {Serial.println ("Button 4"); 112 Number1=4; 113 } 114 115 if (Y>120 && Y<180) //If Button 1 is pressed 116 {Serial.println ("Button 0"); 117 118 Number1=0; 119 } 120 121 122 } 123 124 if (X<135 && X>90) //Detecting Buttons on Column 2 125 { 126 if (Y>0 && Y<60) 127 {Serial.println ("Button 9"); //Button 10 is Pressed 128 129 Number1=9; 130 } 131 132 if (Y>60 && Y<120) 133 {Serial.println ("Button 5"); 134 Number1=5; 135 } 136 137 if (Y>120 && Y<180) 138 {Serial.println ("Button 1"); 139 Number1=1; 140 } 141 142 143 } 144 145 if (X<90 && X>40) //Detecting Buttons on Column 3 146 { 147 if (Y>0 && Y<60) 148 {Serial.println ("Button C"); 149 150 ring=0; 151 ring1=0; 152 ring2=0; 153 ring3=0; 154 ring4=0; 155 156 // IntroScreen(); 157 draw_BoxNButtons(); 158 resistance=0; 159 Number1=0; 160 161// finalvalue1=0; 162 delay(500); 163 164 return; 165 166 } 167 168 if (Y>60 && Y<120) 169 {Serial.println ("Button 6"); 170 Number1=6; 171 } 172 173 if (Y>120 && Y<180) 174 {Serial.println ("Button 2"); 175 Number1=2; 176 } 177 178 } 179 180 if (X<48) //Detecting Buttons on Column 4 181{ 182 if (Y>0 && Y<60) 183 {Serial.println ("Button K"); 184 185 if(ring>3) 186calculation(); 187else 188 draw_BoxNButtons(); 189 190 ring=-1; 191 ring1=0; 192 ring2=0; 193 ring3=0; 194 ring4=0; 195 delay(700); 196 } 197 198 if (Y>60 && Y<120) 199 {Serial.println ("Button 7"); 200 Number1=7; 201 } 202 203 if (Y>120 && Y<180) 204 {Serial.println ("Button 3"); 205 Number1=3; 206 } 207 208 209 } 210 if(!(ring>3 || ring==-1)) 211{ 212 tft.setCursor(55, 28+(20*ring)); 213 tft.setTextColor(RED); 214 tft.setTextSize(2); 215 tft.println(colors[0][Number1]); 216 delay(300); 217 ring++; 218} 219else 220ring++; 221 222} 223 224 225 226 227 228void IntroScreen() 229{tft.fillScreen(BLACK); 230 tft.setCursor (55, 50); 231 tft.setTextSize (3); 232 tft.setTextColor(RED); 233 tft.println("ARDUINO"); 234 tft.setTextColor(YELLOW); 235 tft.setCursor (60, 140); 236 tft.setTextSize (2); 237 tft.println("Resistor "); 238 tft.setCursor (10, 170); 239 tft.println("Color Coding Game"); 240 tft.setCursor (10, 230); 241 tft.setTextColor(BLUE); 242 tft.println("Teach Me Something"); 243 delay(4000); 244 245} 246 247void draw_BoxNButtons() 248{ 249 //Draw the Result Box 250 tft.fillRect(0, 0, 240, 140,BLUE); 251 tft.fillRect(20, 25, 20, 85,WHITE); 252 for(int a=0; a<3;a++) 253 {tft.drawLine(29+a,25,29+a,15,WHITE); 254 tft.drawLine(29+a,80,29+a,120,WHITE); 255 256 } 257 tft.fillRect(20,35,20,3,BLACK); 258 tft.fillRect(20,55,20,3,BLACK); 259 260 tft.fillRect(20,75,20,3,BLACK); 261 tft.fillRect(20,100,20,3,BLACK); 262 263 //Draw First Column 264 tft.fillRect (0,260,60,60,GREY); 265 tft.fillRect (0,200,60,60,YELLOW); 266 tft.fillRect (0,140,60,60,BLACK); 267 268 //Draw Second Column 269 tft.fillRect (60,260,60,60,WHITE); 270 tft.fillRect (60,200,60,60,GREEN); 271 tft.fillRect (60,140,60,60,BROWN); 272 273 //Draw Third Column 274 tft.fillRect (120,260,60,60,BLACK); 275 tft.fillRect (120,200,60,60,BLUE); 276 tft.fillRect (120,140,60,60,RED); 277 278 //Draw 4th Column 279 tft.fillRect (180,260,60,60,BLACK); 280 tft.fillRect (180,200,60,60,MAGENTA); 281 tft.fillRect (180,140,60,60,ORANGE); 282 283 284 //Draw Horizontal Lines 285 for (int h=140; h<=320; h+=60) 286 tft.drawFastHLine(0, h, 240, WHITE); 287 288 //Draw Vertical Lines 289 for (int v=0; v<=240; v+=60) 290 tft.drawFastVLine(v, 140, 240, WHITE); 291 292 //Display keypad lables 293 for (int j=0;j<3;j++) { 294 for (int i=0;i<4;i++) { 295 tft.setCursor(22 + (60*i), 100 + (60*(j+1))); 296 tft.setTextSize(3); 297 tft.setTextColor(WHITE); 298 tft.println(symbol[j][i]); 299 300 } 301 302 303 } 304 305 tft.setTextSize(3); 306 tft.setTextColor(BLACK); 307 tft.setCursor(22 , 220); 308 tft.println("4"); 309 tft.setCursor(82 , 280); 310 tft.println("9"); 311 tft.setTextColor(RED); 312 tft.setCursor(22 , 280); 313 tft.println("8"); 314 tft.fillRect (181,261,60,60,BLACK); 315 316 tft.setTextSize(3); 317 tft.setCursor(195 , 280); 318 tft.println("OK"); 319} 320 321void Ring() 322{ 323if(ring==1) 324ring1=Number1; 325if(ring==2) 326ring2=Number1; 327if(ring==3) 328ring3=Number1; 329if(ring==4) 330ring4=Number1; 331} 332 333 334void calculation() 335{ 336 337 long test; 338 float finalvalue1; 339 int mega=0; 340 341 if(ring3==0) 342 test=1; 343 if(ring3==1) 344 test=10; 345 if(ring3==2) 346 test=100; 347 if(ring3==3) 348 test=1000; 349 if(ring3==4) 350 test=10000; 351 if(ring3==5) 352 {test=1; 353 mega=1;}; 354 if(ring3==6) 355 {test=10; 356 mega=1;} 357 if(ring3==7) 358 {test=100; 359 mega=1;} 360 if(ring3==8) 361 {test=1000; 362 mega=1;} 363 if(ring3==9) 364 {test=10000; 365 mega=1;} 366resistance= (ring1*10+ring2)*test;teac 367Serial.println(resistance); 368Serial.println(ring1); 369Serial.println(ring2); 370Serial.println(ring3); 371 372 373 tft.setTextSize(3); 374tft.setTextColor(WHITE); 375tft.setCursor(145 , 20); 376if(resistance<1000 && mega==0) 377{tft.println(resistance); 378 tft.setCursor(145 , 50); 379tft.print("Ohms"); 380} 381else if(resistance>999 && mega==0) 382{ 383 384 finalvalue1=(float)resistance/1000; 385 tft.print(finalvalue1); 386 tft.setCursor(145 , 60); 387 tft.print("K.Ohm"); 388} 389else 390{ 391 392 finalvalue1=(float)resistance/10; 393 tft.print(finalvalue1); 394 tft.setCursor(145 , 60); 395 tft.print("M.Ohm"); 396} 397 ring=0; 398}
Downloadable files
Pin details of 2.4 inch TFT LCD Shield
Fix the LCD Shield with Arduino UNO
Pin details of 2.4 inch TFT LCD Shield
Comments
Only logged in users can leave comments