• 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 2

By Abhishek Ghosh May 22, 2018 9:43 pm Updated on May 23, 2018

Arduino TFT Touch Screen Calculator (MCUFRIEND) : Part 2

Advertisement

May be, reading the Part 2 of Arduino TFT Touch Screen matter will help you. The touch screen shield I got has ST7789V (0x7789), which is somewhat uncommon. This article is Part 2 of Arduino TFT Touch Screen Calculator By MCUFRIEND. These cheap China used-display stuffs basically have some risk of purchasing. If the driver is rare, you do not have much options. Identifying driver not also that easy. We feel that these web pages will help you :

Vim
1
2
3
misc.ws/2015/01/24/lcd-touch-screen-information/
http://www.rinkydinkelectronics.com/p_utft_analog_clock.php
https://docs.google.com/spreadsheets/d/11NiqGfhY6hEn82NVkdbyhqLUGae0Sy1m_vwhqrpiItQ/edit#gid=1863870689

 

Arduino TFT Touch Screen Calculator (MCUFRIEND)

 

If you notice my model of touch screen :

Arduino TFT Touch Screen Calculator MCUFRIENDPart 2

You’ll notice that it has no commonly seen Home, Message etc icons printed over the lower part. May be the thing was used by Samsung or LG for their mobile. If you dislike to read so much, here is code for you to test :

Advertisement

---

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
#define PORTRAIT  0
#define LANDSCAPE 1
#define TOUCH_ORIENTATION  PORTRAIT
#include <Adafruit_GFX.h>    // Core graphics library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;       // hard-wired for UNO shields anyway.
#include <TouchScreen.h>
#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 BUTTON_X 30
#define BUTTON_Y 123
#define BUTTON_W 51
#define BUTTON_H 50
#define BUTTON_SPACING_X 07
#define BUTTON_SPACING_Y 07
#define BUTTON_TEXTSIZE 2
char buttonlabels[16][5] = { "1", "2", "3","+", "4", "5", "6","-", "7", "8", "9","/","=","0","DEL","x"};
uint16_t buttoncolors[16] = { BLUE,BLUE,BLUE,GREEN,BLUE,BLUE,BLUE,GREEN,BLUE,BLUE,BLUE,GREEN,GREEN,BLUE,RED,BLUE };
Adafruit_GFX_Button buttons[16];
int col=0,row=0,z=0;
#define TEXT_X 5
#define TEXT_Y 25
#define TEXT_W (tft.width()-10)
#define TEXT_H 70
#define TEXT_TSIZE 3
#define TEXT_TCOLOR BLACK
char q;
const int XP=7,XM=A1,YP=A2,YM=6; //240x320 ID=0x7789
const int TS_LEFT=337,TS_RT=653,TS_TOP=797,TS_BOT=495;
// Calibrate values
#define TS_MINX 125
#define TS_MINY 85
#define TS_MAXX 800
#define TS_MAXY 905
uint32_t num1,num2;
char operator_type=-1;
#define TEXT_LEN 10
char textfield[TEXT_LEN+1] = "";
uint8_t textfield_i=0;
uint32_t result=0;
#define MINPRESSURE 400
#define MAXPRESSURE 800
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 350);
TSPoint tp;
boolean n=false;
char test=0;
uint16_t identifier;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  tft.reset();
  identifier = tft.readID();
  tft.begin(identifier);
  tft.fillScreen(WHITE);
  tft.setRotation(0);
  start_screen();
}
void loop()
{
get_button();
    if(q> 0 && q<=16)
        {
          q--;  
    if(get_number(q)!=-1)
      {
        test++;
        if(test==1)
        {
          num1=get_number(q);
        pressed_button();
        animate();
         display_text();
        }
        else if(test==2 && operator_type!=-1){
        num2=get_number(q);
        pressed_button();
        animate();
         display_text();
        test=0;
        }
      }
    else
    if(get_opertator(q)!=-1)
    {
      operator_type=get_opertator(q);
      pressed_button();
      animate();
       display_text();
        
    }else
    if(q==12)
    {display_text();
      switch (operator_type)
      {
        case 0:result=num1+num2;break;
        case 1:result=num1-num2;break;
        case 2:result=num1/num2;break;
        case 3:result=num1*num2;break;
      }
      result_display();
      operator_type=-1;
      test=0;
      num1=0;
     num2=0;
     char textfield[TEXT_LEN+1] = "";
     textfield_i=0;
    n=true;
    }
    else
    if(q==14 && test!=0)
    {
       clr_button();
    test--;
    animate();
     display_text();
    }
    q=0;
   }
}
 
void get_button()
{for (uint8_t b=0; b<16; b++)
    {
      if (buttons[b].contains(tp.x, tp.y))
      {
        buttons[b].press(true);  // tell the button it is pressed
       q=b+1;
      }
      else
       {
        buttons[b].press(false);  // tell the button it is NOT pressed
       }
    }
    }
void animate()
  {
      if (buttons[q].justPressed())
      {
        buttons[q].drawButton(true);  // draw invert!
        delay(10);
        buttons[q].drawButton();
      }
  }
void clr_button()
{
          
    textfield[textfield_i] = 0;
    if (textfield > 0)
    {
      textfield_i--;
      textfield[textfield_i] = ' ';
    }
}
 
 
int get_number(unsigned int num)
{
  switch (num)
  {
    case 0x00: return 1; break;
    case 0x01: return 2; break;
    case 0x02: return 3; break;
    case 0x04: return 4; break;
    case 0x05: return 5; break;
    case 0x06: return 6; break;
    case 0x08: return 7; break;
    case 0x09: return 8; break;
    case 0x0A: return 9; break;
    case 0x0D: return 0; break;
    default: return -1;break;
  }
}
int get_opertator(const char num)
{
  switch (num)
  {
    case 0x03: return 0;break;
    case 0x07: return 1;break;
    case 0x0B: return 2;break;
    case 0x0F: return 3;break;
    default: return -1;break;
  }
}
 
void display_text()
{
  tft.setCursor(TEXT_X + 2, TEXT_Y+10);
  tft.setTextColor(TEXT_TCOLOR, WHITE);
  tft.setTextSize(TEXT_TSIZE);
  tft.print(textfield);
}
void  clear_result()
{
   tft.setCursor(TEXT_X + 2, TEXT_Y+40);
  tft.setTextColor(TEXT_TCOLOR, WHITE);
  tft.setTextSize(TEXT_TSIZE);
  tft.print("     ");
  tft.setCursor(TEXT_X + 2, TEXT_Y+10);
  tft.print("     ");
  
  n=false;
}
void result_display()
{
  tft.setCursor(TEXT_X + 2, TEXT_Y+40);
  tft.setTextColor(TEXT_TCOLOR, WHITE);
  tft.setTextSize(TEXT_TSIZE);
  tft.print('=');
  tft.print(result);
}
void pressed_button()
{
    textfield[textfield_i] = buttonlabels[q][0];    
    textfield_i++;    
    textfield[textfield_i] = 0; // zero terminate
}
 
void button_ini()
{
  for(int i=0;i<4;i++)
{ for(int j=0;j<4;j++)
   creat_button(i,j);  
}
}
//function to creat buttons
void creat_button(int x,int y)
{row=x;col=y;
 
  buttons[z].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X),
                 BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y),    // x, y, w, h, outline, fill, text
                  BUTTON_W, BUTTON_H, BLACK, buttoncolors[z],BLACK,
                  buttonlabels[z], BUTTON_TEXTSIZE);
  buttons[z].drawButton();
  z++;
}
 
void start_screen()
{
  
  tft.fillScreen(WHITE);
  tft.setCursor ((tft.width()/2)-60, 5);
  tft.setTextSize (2);
  tft.setTextColor(BLACK);
  tft.println("CALCULATOR");
  tft.drawRoundRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, 10, BLACK);
    button_ini();
    waitfortouch();
}
 
void drawBorder ()
{// Draw a border
  uint16_t width = tft.width() - 1;
  uint16_t height = tft.height() - 1;
  uint8_t border = 10;
  tft.fillScreen(RED);
  tft.fillRect(border, border, (width - border * 2), (height - border * 2), WHITE);
}
TSPoint waitfortouch()
{  
  do {
    tp= ts.getPoint();
    pinMode(XM, OUTPUT); //Pins configures again for TFT control
    pinMode(YP, OUTPUT);
     } while((tp.z < MINPRESSURE )|| (tp.z > MAXPRESSURE));
 
tp.x = map(tp.x, TS_MINX, TS_MAXX, 0, tft.width());
tp.y = map(tp.y, TS_MINY, TS_MAXY, 0, tft.height());
  return tp;
  
}

For practical purpose, the above code is also available on GitHub as project. The origin of the above thing is from :

Vim
1
https://github.com/shubhamtrivedi95/Calculator-using-arduino/blob/master/calculator/calculator.ino

We also kept the serial text outputs out of various codes :

Vim
1
https://github.com/AbhishekGhosh/MCUFRIEND-ST7789V-TFT-Calculator/blob/master/ST7789V.txt

There is no actually not many more things to write. May be there will be another part in future?

Tagged With arduino touch screen projects , arduino tft touch shield , arduino calculator , Arduino calc tft , arduino touch screen display , arduino touch screen 7 , 7 tft touch screen , arduino calculator touch , web facebook com/abhishek zade 121/friends , arduino mcufriend msglin

This Article Has Been Shared 122 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic 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 2

  • DIY Basic Stand For TM1637 7 Segment LED Display Module

    Is Not It Risky To Use LED Display Unprotected? Here Is How To Build DIY Basic Stand For TM1637 7 Segment LED Display Module With Cardboard.

  • ATtiny Arduino Boards For Cost Saving Projects

    Ready to Use Cheap ATtiny Arduino Boards Available. Here is What to Know About ATtiny Arduino Boards For Cost Saving Projects Before Buying.

  • List of Electronics Prototyping & Project Materials

    Our Illustrated List of Electronics Prototyping & Project Materials is a Helpful Guide to Those Who Lacks Conventional Course on Electronics.

  • How To Play MP3 On Arduino With No Shield, No SD Card

    Here is How to Play MP3 On Arduino With No Shield, No SD Card at Lower Bit Rate for Few Seconds. It is Suggested to Try for Learning Basic.

  • Cheap, Small Arduino Projects With ATtiny 13, ATtiny 10 (Basics)

    You Can Create Cheap, Small Arduino Projects With ATtiny 13, ATtiny 10. They cost $1 or lesser per unit and needs no external components.

Additionally, 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

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

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 (21K Followers)
  • Twitter (5.3k 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

  • Best Powerpoint Templates for Communicating IoT Concepts April 17, 2021
  • How to Build a DIY Water Level Indicator? April 16, 2021
  • How Startups Can Convince the Investors April 14, 2021
  • What to Know About the Cloud Storage Services for Smartphones April 13, 2021
  • WonderFox HD Video Converter Factory Pro Review April 10, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Arduino TFT Touch Screen Calculator (MCUFRIEND) : Part 2," in The Customize Windows, May 22, 2018, April 20, 2021, https://thecustomizewindows.com/2018/05/arduino-tft-touch-screen-calculator-mcufriend-part-2/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

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

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