Cov txheej txheem:

Arduino TFT LCD Touchscreen Calculator: 3 Kauj Ruam
Arduino TFT LCD Touchscreen Calculator: 3 Kauj Ruam

Video: Arduino TFT LCD Touchscreen Calculator: 3 Kauj Ruam

Video: Arduino TFT LCD Touchscreen Calculator: 3 Kauj Ruam
Video: Arduino Touch Screen Tutorial (2.8" TFT ILI 9341) with SD Card Slot 2024, Kaum ib hlis
Anonim
Arduino TFT LCD Touchscreen Calculator
Arduino TFT LCD Touchscreen Calculator

Nyob Zoo Cov Neeg Hauv Cov Lus Qhia no peb yuav kawm paub yuav ua lub laij lej li cas siv Arduino Uno nrog 3.5 TFT LCD Touchscreen zaub. muab cov zauv zauv zauv yooj yim.

Kauj Ruam 1: Yam Koj Xav Tau

Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau
Yam Koj Xav Tau

Rau txoj haujlwm no koj yuav xav tau cov khoom hauv qab no: 3.5 TFT LCD DISPLAYARDUINO UNO

Kauj Ruam 2: Txhim Kho TFT Display Library hauv Arduino IDE

Txhim kho TFT Display Library hauv Arduino IDE
Txhim kho TFT Display Library hauv Arduino IDE

Peb tab tom siv SPFD5408 Library:

kom tau txais qhov arduino calculator code ua haujlwm. Nov yog hloov kho tsev qiv ntawv ntawm Adafruit thiab tuaj yeem ua haujlwm tau zoo nrog peb cov LCD TFT Module. Nws yog ib qho tseem ceeb heev rau koj los teeb lub tsev qiv ntawv no hauv koj Arduino IDE lossis cov haujlwm no txhawm rau suav ua yam tsis muaj qhov yuam kev. Muaj nyem rau clone lossis rub tawm thiab xaiv "Download ZIP". Ib daim ntawv zip yuav rub tawm tam sim no, qhib Arduino IDE thiab xaiv Sketch -> Xws li Librarey -> Ntxiv. ZIP tsev qiv ntawv. Lub qhov rai browser yuav qhib mus rau ZIP cov ntaub ntawv thiab nyem "OK". Koj yuav tsum pom "Cov tsev qiv ntawv ntxiv rau koj Lub Tsev Qiv Ntawv" nyob rau hauv qab sab laug ntawm Arduino.

Kauj Ruam 3: Upload Tus lej Xauv

Upload tus lej Tshuab xam zauv
Upload tus lej Tshuab xam zauv
Upload tus lej Tshuab xam zauv
Upload tus lej Tshuab xam zauv

Tom qab txhim kho lub tsev qiv ntawv txuas cov zaub rau Arduino thiab luam cov cai hauv qab no & upload nws mus rau Arduino./*_Import Libraries _*/#suav nrog "SPFD5408_Adafruit_GFX.h" // Core graphics library#suav nrog "SPFD5408_Adafruit_TFTLCD.h" // Hardware-specific lub tsev qiv ntawv#suav nrog "SPFD5408_TouchScreen.h"/*_ End of Libraries _*//*_ Txhais LCD pins (Kuv tau kos npe rau lub neej ntawd) _*/#txhais YP A1 // yuav tsum yog tus pin analog, siv "Ib qho" cim! txhais XM A2 // yuav tsum yog tus lej sib piv, siv "An" notation!#txhais YM 7 // tuaj yeem yog tus lej digital#txhais XP 6 // tuaj yeem yog tus lej digital#txhais LCD_CS A3#txhais LCD_CD A2#txhais LCD_WR A1#txhais LCD_RD A0#txhais LCD_RESET A4/*_ Xaus qhov kev txhais _*//*_ Muab cov npe rau xim thiab siab _*/#txhais WHITE 0x0000 // Dub-> Dawb#txhais YELLOW 0x001F // Xiav-> Daj#txhais CYAN 0xF800 // Red-> Cyan#define PINK 0x07E0 // Green-> Pink#define RED 0x07FF // Cyan-> Red#define GREEN 0xF81F // Pink-> Green #define BLUE 0xFFE0 // Daj- > Xiav#txhais BLACK 0xFFFF // Dawb-> Dub#txhais MINPRESSURE 10#txhais MAXPRESSURE 1000/*_ Ua Haujlwm _*//*_ Calibrate TFT LCD _*/#txhais TS_MINX 125#txhais TS_MINY 85#txhais TS_MAXX 965#txhais TS_MAXY _ End of Calibration _*/TouchScreen ts = TouchScreen (XP, YP, XM, YM, 300); // 300 yog qhov rhiab heev Adafruit_TFTLCD tft (LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // Pib sib txuas lus nrog LCDString cim [4] [4] = {{"7", "8", "9", "/"}, {"4", "5", "6", "*"}, {"1", "2", "3", "-"}, {"C", "0", "=", "+"}}; tus X, Y; ntev Num1, Num2, Number; char kev; boolean result = cuav; teeb tsa tsis muaj dabtsis () {Serial.begin (9600); // Siv cov ntsuas saib rau debugging tft.reset (); // Ib txwm rov pib dua thaum pib tft.begin (0x9341); // Kuv lub LCD siv LIL9341 Interface tsav IC tft.setRotation (2); // Kuv nyuam qhuav ua kom lub hwj chim lub ntsej muag nce - yeem tft.fillScreen (WHITE); IntroScreen (); draw_BoxNButtons (); } void loop () {TSPoint p = waitTouch (); X = p.y; Y = p.x; // Serial.print (X); Serial.print (','); Serial.println (Y); // + "" + Y); DetectButtons (); yog (qhov tshwm sim == muaj tseeb) CalculateResult (); DisplayResult (); ncua (300);} TSPoint waitTouch () {TSPoint p; ua {p = ts.getPoint (); tus pinMode (XM, OUTPUT); tus pinMode (YP, OUTPUT); } thaum ((p.z MAXPRESSURE)); p.x = map (p.x, TS_MINX, TS_MAXX, 0, 320); p.y = map (p.y, TS_MINY, TS_MAXY, 0, 240);; xa p;} tsis muaj dabtsis DetectButtons () {yog (X0) // Txheeb xyuas khawm ntawm kab 1 {yog (Y> 0 && Y <85) // Yog tias rho tawm khawm raug nias {Serial.println ("Button Cancel"); Number = Num1 = Num2 = 0; tshwm sim = tsis tseeb;} yog (Y> 85 && Y <140) // Yog tias khawm 1 raug nias {Serial.println ("Khawm 1"); yog (Tus lej == 0) Tus lej = 1; lwm tus lej = (Tus lej*10) + 1; // Nias ob zaug} yog (Y> 140 && Y <192) // Yog tias khawm 4 raug nias {Serial.println ("Khawm 4"); yog (Tus lej == 0) Tus lej = 4; lwm tus lej = (Tus lej*10) + 4; // Nias ob zaug} yog (Y> 192 && Y <245) // Yog tias khawm 7 raug nias {Serial.println ("Khawm 7"); yog (Tus lej == 0) Tus lej = 7; lwm tus lej = (Tus lej*10) + 7; // Nias ob zaug}} yog (X50) // Txheeb Pom Cov Khawm ntawm Kab 2 {yog (Y> 0 && Y <85) {Serial.println ("Khawm 0"); // Khawm 0 yog Nias yog (Tus lej == 0) Tus lej = 0; lwm tus lej = (Tus lej*10) + 0; // Nias ob zaug} yog (Y> 85 && Y <140) {Serial.println ("Khawm 2"); yog (Tus lej == 0) Tus lej = 2; lwm tus lej = (Tus lej*10) + 2; // Nias ob zaug} yog (Y> 140 && Y <192) {Serial.println ("Khawm 5"); yog (Tus lej == 0) Tus lej = 5; lwm tus lej = (Tus lej*10) + 5; // Nias twic} yog (Y> 192 && Y <245) {Serial.println ("Khawm 8"); yog (Tus lej == 0) Tus lej = 8; lwm tus lej = (Tus lej*10) + 8; // Nias twic}} yog (X105) // Txheeb xyuas Cov Nyees khawm ntawm Kab 3 {yog (Y> 0 && Y <85) {Serial.println ("Button Equal"); Num2 = Tus lej; result = tseeb; } yog (Y> 85 && Y <140) {Serial.println ("Khawm 3"); yog (Tus lej == 0) Tus lej = 3; lwm tus lej = (Tus lej*10) + 3; // Nias ob zaug} yog (Y> 140 && Y <192) {Serial.println ("Khawm 6"); yog (Tus lej == 0) Tus lej = 6; lwm tus lej = (Tus lej*10) + 6; // Nias ob zaug} yog (Y> 192 && Y <245) {Serial.println ("Khawm 9"); yog (Tus lej == 0) Tus lej = 9; lwm tus lej = (Tus lej*10) + 9; // Nias ob zaug}} yog (X165) // Txheeb xyuas Cov Nyees khawm ntawm Kab 3 {Num1 = Tus lej; Zauv = 0; tft.setCursor (200, 20); tft.setTextColor (RED); yog (Y> 0 && Y <85) {Serial.println ("Ntxiv"); kev = 1; tft.println ('+');} yog (Y> 85 && Y <140) {Serial.println ("rho tawm"); kev = 2; tft.println ('-');} yog (Y> 140 && Y <192) {Serial.println ("Multiplication"); kev = 3; tft.println ('*');} yog (Y> 192 && Y <245) {Serial.println ("Devesion"); kev = 4; tft.println ('/');} ncua (300); }} void CalculateResult () {if (action == 1) Number = Num1+Num2; if (action == 2) Number = Num1-Num2; yog (kev ua == 3) Tus lej = Num1*Num2; if (action == 4) Number = Num1/Num2; } void DisplayResult () {tft.fillRect (0, 0, 240, 80, CYAN); // tshem tawm qhov tshwm sim lub thawv tft.setCursor (10, 20); tft.setTextSize (4); tft.setTextColor (BLACK); tft.println (Naj Npawb); // hloov kho tus nqi tshiab} tsis muaj dab tsi IntroScreen () {tft.setCursor (55, 120); tft.setTextSize (3); tft.setTextColor (RED); tft.println ("ARDUINO"); tft.setCursor (30, 160); tft.println ("CALCULATOR"); tft.setCursor (30, 220); tft.setTextSize (2); tft.setTextColor (XEEB); tft.println ("-Circut Digest"); ncua (1800);} tsis muaj dabtsis draw_BoxNButtons () {// Kos lub thawv tshwm tft.fillRect (0, 0, 240, 80, CYAN); // Kos Thawj Kab tft.fillRect (0, 260, 60, 60, RED); tft.fillRect (0, 200, 60, 60, BLACK); tft.fillRect (0, 140, 60, 60, BLACK); tft.fillRect (0, 80, 60, 60, BLACK); // Kos Peb Kab tft.fillRect (120, 260, 60, 60, GREEN); tft.fillRect (120, 200, 60, 60, BLACK); tft.fillRect (120, 140, 60, 60, BLACK); tft.fillRect (120, 80, 60, 60, BLACK); // Draw Secound & Fourth Column rau (int b = 260; b> = 80; b- = 60) {tft.fillRect (180, b, 60, 60, BLUE); tft.fillRect (60, b, 60, 60, BLACK);} // Kos Kab Kab Kab rau (int h = 80; h <= 320; h+= 60) tft.drawFastHLine (0, h, 240, WHITE); // Kos Kab Ntsug rau (int v = 0; v <= 240; v+= 60) tft.drawFastVLine (v, 80, 240, WHITE); // Zaub cov ntawv tseem ceeb rau (int j = 0; j <4; j ++) {rau (int i = 0; i <4; i ++) {tft.setCursor (22+(60*i), 100+(60* j)); tft.setTextSize (3); tft.setTextColor (WHITE); tft.println (cim [j] ); }}} Tom qab tso cov lej koj tuaj yeem pom lub laij lej ua haujlwm hauv koj cov zaub li kuv thiab tam sim no koj tuaj yeem ua cov lej zauv yooj yim ntawm qhov no. Yog li muaj kev lom zem ua koj tus kheej lub laij lej nrog Arduino UNO.

Pom zoo: