Skip to content

Commit 2a00dd2

Browse files
committed
Added more comments to calculator example
1 parent e1bafb7 commit 2a00dd2

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

examples/Inkplate6PLUS/Projects/Inkplate6PLUS_Calculator/Inkplate6PLUS_Calculator.ino

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void setup()
5656

5757
void loop()
5858
{
59-
// Periodically check touchscreen
59+
// Periodically check touchscreen and perform events based on touches
6060
keysEvents();
6161
delay(20);
6262
}
@@ -136,19 +136,21 @@ void keysEvents()
136136
numOfDecimalDigitsOnCurrentNumber = 0;
137137
}
138138

139-
if (display.touchInArea(900, 650, 100, 100) && (op == ' ') && (rightNumPos > 0))
139+
if (display.touchInArea(900, 650, 100, 100) && (op == ' ') && (rightNumPos > 0)) // Sum
140140
{
141141
text18_cursor_x -= X_REZ_OFFSET;
142142
text18_content = text18_content + " + ";
143143
op = '+';
144144
decimalPointOnCurrentNumber = false;
145145
numOfDecimalDigitsOnCurrentNumber = 0;
146+
147+
// Clear screen and redraw using partialUpdate
146148
display.clearDisplay();
147149
mainDraw();
148150
display.partialUpdate();
149151
}
150152

151-
if (display.touchInArea(700, 650, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
153+
if (display.touchInArea(700, 650, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 0
152154
{
153155
text18_cursor_x -= X_REZ_OFFSET;
154156
text18_content = text18_content + "0";
@@ -157,6 +159,8 @@ void keysEvents()
157159
{
158160
numOfDecimalDigitsOnCurrentNumber++;
159161
}
162+
163+
// Clear screen and redraw using partialUpdate
160164
display.clearDisplay();
161165
mainDraw();
162166
display.partialUpdate();
@@ -167,10 +171,12 @@ void keysEvents()
167171
}
168172
}
169173

170-
if (display.touchInArea(600, 650, 100, 100) && !decimalPointOnCurrentNumber && numOfDigitsEntered < 6)
174+
if (display.touchInArea(600, 650, 100, 100) && !decimalPointOnCurrentNumber && numOfDigitsEntered < 6) // Decimal point
171175
{
172176
text18_cursor_x -= X_REZ_OFFSET;
173177
text18_content = text18_content + ".";
178+
179+
// Clear screen and redraw using partialUpdate
174180
display.clearDisplay();
175181
mainDraw();
176182
display.partialUpdate();
@@ -179,22 +185,26 @@ void keysEvents()
179185
{
180186
++rightNumPos;
181187
}
188+
189+
// Set flag that decimal point has been used
182190
decimalPointOnCurrentNumber = true;
183191
}
184192

185-
if (display.touchInArea(900, 550, 100, 100) && (op == ' ') && (rightNumPos > 0))
193+
if (display.touchInArea(900, 550, 100, 100) && (op == ' ') && (rightNumPos > 0)) // Subtraction
186194
{
187195
text18_cursor_x -= X_REZ_OFFSET;
188196
text18_content = text18_content + " - ";
189197
op = '-';
190198
decimalPointOnCurrentNumber = false;
191199
numOfDecimalDigitsOnCurrentNumber = 0;
200+
201+
// Clear screen and redraw using partialUpdate
192202
display.clearDisplay();
193203
mainDraw();
194204
display.partialUpdate();
195205
}
196206

197-
if (display.touchInArea(800, 550, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
207+
if (display.touchInArea(800, 550, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 3
198208
{
199209
text18_cursor_x -= X_REZ_OFFSET;
200210
text18_content = text18_content + "3";
@@ -203,6 +213,8 @@ void keysEvents()
203213
{
204214
numOfDecimalDigitsOnCurrentNumber++;
205215
}
216+
217+
// Clear screen and redraw using partialUpdate
206218
display.clearDisplay();
207219
mainDraw();
208220
display.partialUpdate();
@@ -213,7 +225,7 @@ void keysEvents()
213225
}
214226
}
215227

216-
if (display.touchInArea(700, 550, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
228+
if (display.touchInArea(700, 550, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 2
217229
{
218230
text18_cursor_x -= X_REZ_OFFSET;
219231
text18_content = text18_content + "2";
@@ -222,6 +234,8 @@ void keysEvents()
222234
{
223235
numOfDecimalDigitsOnCurrentNumber++;
224236
}
237+
238+
// Clear screen and redraw using partialUpdate
225239
display.clearDisplay();
226240
mainDraw();
227241
display.partialUpdate();
@@ -232,7 +246,7 @@ void keysEvents()
232246
}
233247
}
234248

235-
if (display.touchInArea(600, 550, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
249+
if (display.touchInArea(600, 550, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 1
236250
{
237251
text18_cursor_x -= X_REZ_OFFSET;
238252
text18_content = text18_content + "1";
@@ -241,6 +255,8 @@ void keysEvents()
241255
{
242256
numOfDecimalDigitsOnCurrentNumber++;
243257
}
258+
259+
// Clear screen and redraw using partialUpdate
244260
display.clearDisplay();
245261
mainDraw();
246262
display.partialUpdate();
@@ -251,19 +267,21 @@ void keysEvents()
251267
}
252268
}
253269

254-
if (display.touchInArea(900, 450, 100, 100) && (op == ' ') && (rightNumPos > 0))
270+
if (display.touchInArea(900, 450, 100, 100) && (op == ' ') && (rightNumPos > 0)) // X
255271
{
256272
text18_cursor_x -= X_REZ_OFFSET;
257273
text18_content = text18_content + " x ";
258274
op = 'x';
259275
decimalPointOnCurrentNumber = false;
260276
numOfDecimalDigitsOnCurrentNumber = 0;
277+
278+
// Clear screen and redraw using partialUpdate
261279
display.clearDisplay();
262280
mainDraw();
263281
display.partialUpdate();
264282
}
265283

266-
if (display.touchInArea(800, 450, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
284+
if (display.touchInArea(800, 450, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 6
267285
{
268286
text18_cursor_x -= X_REZ_OFFSET;
269287
text18_content = text18_content + "6";
@@ -272,6 +290,8 @@ void keysEvents()
272290
{
273291
numOfDecimalDigitsOnCurrentNumber++;
274292
}
293+
294+
// Clear screen and redraw using partialUpdate
275295
display.clearDisplay();
276296
mainDraw();
277297
display.partialUpdate();
@@ -282,7 +302,7 @@ void keysEvents()
282302
}
283303
}
284304

285-
if (display.touchInArea(700, 450, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
305+
if (display.touchInArea(700, 450, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 5
286306
{
287307
text18_cursor_x -= X_REZ_OFFSET;
288308
text18_content = text18_content + "5";
@@ -291,6 +311,8 @@ void keysEvents()
291311
{
292312
numOfDecimalDigitsOnCurrentNumber++;
293313
}
314+
315+
// Clear screen and redraw using partialUpdate
294316
display.clearDisplay();
295317
mainDraw();
296318
display.partialUpdate();
@@ -301,7 +323,7 @@ void keysEvents()
301323
}
302324
}
303325

304-
if (display.touchInArea(600, 450, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
326+
if (display.touchInArea(600, 450, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 4
305327
{
306328
text18_cursor_x -= X_REZ_OFFSET;
307329
text18_content = text18_content + "4";
@@ -310,6 +332,8 @@ void keysEvents()
310332
{
311333
numOfDecimalDigitsOnCurrentNumber++;
312334
}
335+
336+
// Clear screen and redraw using partialUpdate
313337
display.clearDisplay();
314338
mainDraw();
315339
display.partialUpdate();
@@ -320,19 +344,21 @@ void keysEvents()
320344
}
321345
}
322346

323-
if (display.touchInArea(900, 350, 100, 100) && (op == ' ') && (rightNumPos > 0))
347+
if (display.touchInArea(900, 350, 100, 100) && (op == ' ') && (rightNumPos > 0)) // Division
324348
{
325349
text18_cursor_x -= X_REZ_OFFSET;
326350
text18_content = text18_content + " / ";
327351
op = '/';
328352
decimalPointOnCurrentNumber = false;
329353
numOfDecimalDigitsOnCurrentNumber = 0;
354+
355+
// Clear screen and redraw using partialUpdate
330356
display.clearDisplay();
331357
mainDraw();
332358
display.partialUpdate();
333359
}
334360

335-
if (display.touchInArea(800, 350, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
361+
if (display.touchInArea(800, 350, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 9
336362
{
337363
text18_cursor_x -= X_REZ_OFFSET;
338364
text18_content = text18_content + "9";
@@ -341,6 +367,8 @@ void keysEvents()
341367
{
342368
numOfDecimalDigitsOnCurrentNumber++;
343369
}
370+
371+
// Clear screen and redraw using partialUpdate
344372
display.clearDisplay();
345373
mainDraw();
346374
display.partialUpdate();
@@ -351,7 +379,7 @@ void keysEvents()
351379
}
352380
}
353381

354-
if (display.touchInArea(700, 350, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
382+
if (display.touchInArea(700, 350, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 8
355383
{
356384
text18_cursor_x -= X_REZ_OFFSET;
357385
text18_content = text18_content + "8";
@@ -360,6 +388,8 @@ void keysEvents()
360388
{
361389
numOfDecimalDigitsOnCurrentNumber++;
362390
}
391+
392+
// Clear screen and redraw using partialUpdate
363393
display.clearDisplay();
364394
mainDraw();
365395
display.partialUpdate();
@@ -370,7 +400,7 @@ void keysEvents()
370400
}
371401
}
372402

373-
if (display.touchInArea(600, 350, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2)
403+
if (display.touchInArea(600, 350, 100, 100) && numOfDigitsEntered < 6 && numOfDecimalDigitsOnCurrentNumber < 2) // 7
374404
{
375405
text18_cursor_x -= X_REZ_OFFSET;
376406
text18_content = text18_content + "7";
@@ -379,6 +409,8 @@ void keysEvents()
379409
{
380410
numOfDecimalDigitsOnCurrentNumber++;
381411
}
412+
413+
// Clear screen and redraw using partialUpdate
382414
display.clearDisplay();
383415
mainDraw();
384416
display.partialUpdate();
@@ -390,6 +422,7 @@ void keysEvents()
390422
}
391423
}
392424

425+
// Do calculation based on inputs
393426
float calculate()
394427
{
395428
double res = 0;

0 commit comments

Comments
 (0)