• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Arduino TFT Touch Screen Calculator (MCUFRIEND) : Part 1

By Abhishek Ghosh January 24, 2018 9:06 am Updated on May 23, 2018

Arduino TFT Touch Screen Calculator (MCUFRIEND) : Part 1

Advertisement

In our previously published article we talked about MCUFRIEND TFT Touch Screen. Arduino TFT Touch Screen Calculator is an Easy Example of Practical Deployment of Programmable Microcontroller From the Libraries. It is important to understand that this guide will only supply codes which may be buggy on different “models” of MCUFRIEND TFT Touch Screens. I named this article as “Part 1” for those bugs and no practical improvement of others codes. What code will work for me may not work for your same one (however you’ll not see a blank white screen) or you’ll see mirror image. Frankly, there is no question of circuit diagram for a shield with Arduino UNO. Simply snap on the shield on Arduino UNO.

 

Arduino TFT Touch Screen Calculator (MCUFRIEND)

 

Below code is for your understanding and matching with the examples from MCUFRIEND_KBV example libraries, it will only show the keys. This is how the keyboard is drawn, you can change the colors, tweak. void loop() is empty. The code actually not respond to touch, it is only for checking the keys :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#include <SPI.h>          // f.k. for Arduino-1.5.2
#include "TouchScreen_kbv.h"
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
//#include <Adafruit_TFTLCD.h>
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// Assign human-readable names to some common 16-bit color values:
#defineBLACK   0x0000
#defineBLUE    0x001F
#defineRED     0xF800
#defineGREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
 
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
String Key[4][4] = {
  { "7", "8", "9", "/" },
  { "4", "5", "6", "*" },
  { "1", "2", "3", "-" },
  { "C", "0", "=", "+" }
};
String N1, N2, ShowSC, opt;
bool updata=false;
float answers=-1;
void setup() {
  Serial.begin(9600);
  tft.reset();
  tft.begin(0x9341); // SDFP5408
  tft.setRotation(0);
  tft.fillScreen(BLACK);
  tft.fillRect(0, 80, 240, 240, WHITE);
  tft.drawFastHLine(0, 80, 240, BLACK);
  tft.drawFastHLine(0, 140, 240, BLACK);
  tft.drawFastHLine(0, 200, 240, BLACK);
  tft.drawFastHLine(0, 260, 240, BLACK);
  tft.drawFastHLine(0, 320-1, 240, BLACK);
  tft.drawFastVLine(0, 80, 240, BLACK);
  tft.drawFastVLine(60, 80, 240, BLACK);
  tft.drawFastVLine(120, 80, 240, BLACK);
  tft.drawFastVLine(180, 80, 240, BLACK);
  tft.drawFastVLine(240-1, 80, 240, BLACK);
  for (int y=0;y<4;y++) {
    for (int x=0;x<4;x++) {
      tft.setCursor(22 + (60*x), 100 + (60*y));
      tft.setTextSize(3);
      tft.setTextColor(BLACK);
      tft.println(Key[y][x]);
    }
  }
}
void loop() {
}

If with the above code you see everything fine but digits mirrored, then possibly you have some slightly different hardware, you probably need to tweak the like tft.setRotation. You can perform Google search to fix it. It is not big matter.

Advertisement

---

Arduino TFT Touch Screen Calculator MCUFRIEND

What others did so far, they used this library :

Vim
1
https://github.com/JoaoLopesF/SPFD5408

And used the below code from maxpromer (on GitHub) :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
 
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
 
#include <SPFD5408_TouchScreen.h>
 
 
 
#define YP A1  // must be an analog pin, use "An" notation!
 
#define XM A2  // must be an analog pin, use "An" notation!
 
#define YM 7   // can be a digital pin
 
#define XP 6   // can be a digital pin
 
 
 
// Calibrate values
 
#define TS_MINX 125
 
#define TS_MINY 85
 
#define TS_MAXX 965
 
#define TS_MAXY 905
 
 
 
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
 
 
 
#define LCD_CS A3
 
#define LCD_CD A2
 
#define LCD_WR A1
 
#define LCD_RD A0
 
// optional
 
#define LCD_RESET A4
 
 
 
// Assign human-readable names to some common 16-bit color values:
 
#define BLACK   0x0000
 
#define BLUE    0x001F
 
#define RED     0xF800
 
#define GREEN   0x07E0
 
#define CYAN    0x07FF
 
#define MAGENTA 0xF81F
 
#define YELLOW  0xFFE0
 
#define WHITE   0xFFFF
 
 
 
#define MINPRESSURE 10
 
#define MAXPRESSURE 1000
 
 
 
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
 
 
 
String Key[4][4] = {
 
  { "7", "8", "9", "/" },
 
  { "4", "5", "6", "*" },
 
  { "1", "2", "3", "-" },
 
  { "C", "0", "=", "+" }
 
};
 
 
 
String N1, N2, ShowSC, opt;
 
bool updata=false;
 
float answers=-1;
 
 
 
void setup() {
 
  Serial.begin(9600);
 
  tft.reset();
 
  tft.begin(0x9341); // SDFP5408
 
  tft.setRotation(2);
 
  tft.fillScreen(BLACK);
 
  
 
  tft.fillRect(0, 80, 240, 240, WHITE);
 
  tft.drawFastHLine(0, 80, 240, BLACK);
 
  tft.drawFastHLine(0, 140, 240, BLACK);
 
  tft.drawFastHLine(0, 200, 240, BLACK);
 
  tft.drawFastHLine(0, 260, 240, BLACK);
 
  tft.drawFastHLine(0, 320-1, 240, BLACK);
 
 
 
  tft.drawFastVLine(0, 80, 240, BLACK);
 
  tft.drawFastVLine(60, 80, 240, BLACK);
 
  tft.drawFastVLine(120, 80, 240, BLACK);
 
  tft.drawFastVLine(180, 80, 240, BLACK);
 
  tft.drawFastVLine(240-1, 80, 240, BLACK);
 
 
 
  for (int y=0;y<4;y++) {
 
    for (int x=0;x<4;x++) {
 
      tft.setCursor(22 + (60*x), 100 + (60*y));
 
      tft.setTextSize(3);
 
      tft.setTextColor(BLACK);
 
      tft.println(Key[y][x]);
 
    }
 
  }
 
}
 
 
 
void loop() {
 
  TSPoint p = waitTouch();
 
  Serial.println(p.x);
 
  updata = false;
 
  for (int i1=0;i1<4;i1++) {
 
    for (int i2=0;i2<4;i2++) {
 
      if ((p.x>=240-((i1+1)*60)+1&&p.x<=240-(i1*60)-1)&&(p.y>=(i2*60)+1&&p.y<=((i2+1)*60)-1)) {
 
        if ((i1<=2&&i2<=2)||(i1==3&&i2==1)) {
 
          if (opt==0) {
 
            if (answers!=-1) answers = -1;
 
            N1 = N1 + Key[i1][i2];
 
            ShowSC = N1;
 
          } else {
 
            N2 = N2 + Key[i1][i2];
 
            ShowSC = opt + N2;
 
          }
 
        } else {
 
          if (Key[i1][i2]=="C") {
 
            N1 = N2 = "";
 
            opt = "";
 
            answers = 0;
 
            ShowSC = N1;
 
          } else if (i2==3) {
 
            if (N1=="") N1 = String(answers);
 
            opt = Key[i1][i2];
 
            ShowSC = Key[i1][i2];
 
          } else if (Key[i1][i2]=="=") {
 
            if (opt=="+") answers = N1.toInt() + N2.toInt();
 
            else if (opt=="-") answers = N1.toInt() - N2.toInt();
 
            else if (opt=="*") answers = N1.toInt() * N2.toInt();
 
            else if (opt=="/") answers = N1.toInt() / N2.toInt();
 
            N1 = N2 = opt = "";
 
            ShowSC = answers;
 
          }
 
        }
 
        updata = true;
 
      }
 
    }
 
  }
 
  
 
  if (updata) {
 
    tft.fillRect(0, 0, 240, 80, BLACK);
 
  
 
    tft.setCursor(10, 10);
 
    tft.setTextSize(3);
 
    tft.setTextColor(WHITE);
 
    tft.println(ShowSC);
 
  }
 
  delay(300);
 
}
 
 
 
TSPoint waitTouch() {
 
  TSPoint p;
 
  do {
 
    p = ts.getPoint();
 
    pinMode(XM, OUTPUT);
 
    pinMode(YP, OUTPUT);
 
  } while((p.z < MINPRESSURE )|| (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);;
 
  return p;
 
}

It is kind of beta version of progress and a self-reminder. You can proceed to read Part 2 of this effort.

Tagged With MCUfriend , \\63 131 137 247\Deployment\TOUCH\SCIX\setup exe , mcufriend com , arduino taschenrechner tft display , mcufriend button , mcufriend library#define PIN_OUTPUT(p b) , arduino UNO CLOCK CODE WITH MCU KBV DISPLAY , mcufriend tft library , arduino tft lcd , file://209 235 232 105/Deployment/TOUCH/SCIX
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Arduino TFT Touch Screen Calculator (MCUFRIEND) : Part 1

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Arduino TFT Touch Screen Calculator (MCUFRIEND) : Part 2

    Here is Part 2 of Arduino TFT Touch Screen Calculator By MCUFRIEND. This particular one has ST7789V (0x7789), which is somewhat less found.

  • Arduino TFT Touch Screen Shield (MCUFRIEND) : Getting Started

    Here is Getting Started Guide For Arduino TFT Touch Screen Shield Manufactured by MCUFRIEND. This is Possibly the Cheapest 2.4″ Color Display For Arduino.

  • Graphing With Arduino on TFT LCD Color Display : Part I

    Graphing With Arduino on TFT LCD Color Display Probably a Needed Matter to Many Users. Graphing Can Become Difficult On Display With Less Known Drivers.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • How to Install Appwrite as a Backend ServerJune 8, 2023
  • What is Application Lifecycle ManagementJune 8, 2023
  • How to Add Auto Anchor to WordPress HeadingsJune 7, 2023
  • Self-Hosted Fonts vs. Cloud-Hosted FontsJune 7, 2023
  • How to Restrict Certain Posts or Categories In WordPress by CountryJune 6, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT