1+ /* *
2+ **************************************************
3+ * @file Inkplate6_Read_Touchpads.ino
4+ * @brief Uses the built-in capacitive touchpads on Inkplate 6 to control
5+ * a counter displayed on the screen.
6+ *
7+ * @details This example demonstrates how to use the three capacitive
8+ * touchpads integrated on the Inkplate 6 PCB. These pads are
9+ * labeled 1, 2, and 3 and function as simple touch-sensitive
10+ * switches that can be used for user input.
11+ *
12+ * The sketch continuously reads the state of the touchpads using
13+ * display.touchpad.read(). Each pad performs a specific action on
14+ * a counter displayed on the screen:
15+ *
16+ * - Pad 1 decreases the number
17+ * - Pad 2 resets the number to zero
18+ * - Pad 3 increases the number
19+ *
20+ * The example uses 1-bit display mode and partial updates to keep
21+ * screen refreshes fast. After several partial updates, a full
22+ * refresh is automatically performed to maintain display quality.
23+ *
24+ * Requirements:
25+ * - Board: Soldered Inkplate 6
26+ * - Hardware: Inkplate 6, USB cable
27+ * - Extra: none
28+ *
29+ * Configuration:
30+ * - Boards Manager -> Inkplate Boards -> Soldered Inkplate6
31+ * - Serial settings: not used in this example
32+ *
33+ * Don't have Inkplate Boards in Arduino Boards Manager?
34+ * See https://docs.soldered.com/inkplate/10/quick-start-guide/
35+ *
36+ * How to use:
37+ * 1) Select Soldered Inkplate6 in Arduino IDE and upload the sketch.
38+ * 2) After startup, a number appears in the center of the display.
39+ * 3) Touch the pads on the bottom of the PCB:
40+ * - Touch pad 1 to decrease the number.
41+ * - Touch pad 2 to reset the number to zero.
42+ * - Touch pad 3 to increase the number.
43+ * 4) The display updates each time a pad is touched.
44+ *
45+ * Expected output:
46+ * - Display: A large number that changes according to touchpad input.
47+ * - Display: Symbols "-", "0", and "+" printed above the touchpads as visual
48+ * indicators of their functions.
49+ *
50+ * Notes:
51+ * - Display mode: 1-bit black-and-white (INKPLATE_1BIT).
52+ * - Partial updates are used for faster refresh. After ~20 partial updates,
53+ * a full refresh is performed automatically.
54+ * - Capacitive touchpads are sensitive to environment and grounding and may
55+ * behave differently depending on humidity, grounding, or enclosures.
56+ * - touchpad.read() returns 1 when the pad is touched and 0 when it is not.
57+ *
58+ * Docs: https://docs.soldered.com/inkplate
59+ * Support: https://forum.soldered.com/
60+ *
61+ * @author Soldered
62+ * @date 2020-07-15
63+ * @license GNU GPL V3
64+ **************************************************/
65+
66+
67+ #include " Inkplate.h" // Include Inkplate library to the sketch
68+ Inkplate display (INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
69+
70+ int number = 0 ; // Variable that stores our number
71+ int n = 0 ; // Variable that keeps track on how many times display is partially updated
72+ void setup ()
73+ {
74+ display.begin (); // Init Inkplate library (you should call this function ONLY ONCE)
75+ display.clearDisplay (); // Clear frame buffer of display
76+ display.display (); // Put clear image on display
77+ display.setTextSize (5 ); // Set text scaling to five (text will be five times bigger)
78+ display.setTextColor (BLACK, WHITE); // Set text color to black and background color to white
79+ displayNumber (); // Call our function to display nubmer on screen
80+ }
81+
82+ void loop ()
83+ {
84+ if (display.touchpad .read (1 ))
85+ { // Check if first pad has been touched. If it is, decrement the number and refresh the screen.
86+ number--;
87+ displayNumber ();
88+ }
89+
90+ if (display.touchpad .read (2 ))
91+ { // If you touched second touchpad, set number to zero and refresh screen by calling our displayNumber() function
92+ number = 0 ;
93+ displayNumber ();
94+ }
95+
96+ if (display.touchpad .read (3 ))
97+ { // If you touched third touchpad, incerement the number and refresh the screen.
98+ number++;
99+ displayNumber ();
100+ }
101+ delay (100 ); // Wait a little bit between readings.
102+ }
103+
104+ // Function that will write you number to screen
105+ void displayNumber ()
106+ {
107+ display.clearDisplay (); // First, lets delete everything from frame buffer
108+ display.setCursor (385 , 280 ); // Set print cursor at X=385, Y=280 (roughly in the middle of the screen)
109+ display.print (number, DEC); // Print the number
110+ display.setCursor (255 , 560 ); // Set new print position (right above first touchpad)
111+ display.print (' -' ); // Print minus sign
112+ display.setCursor (385 , 560 ); // Set new print position (right above second touchpad)
113+ display.print (' 0' ); // Print zero
114+ display.setCursor (520 , 560 ); // Set new print position (right above third touchpad)
115+ display.print (' +' ); // Print plus sign
116+ if (n > 20 )
117+ { // Chech if screen has been partially refreshed more than 20 times. If it is, do a full refresh. If is not, do a
118+ // partial refresh
119+ display.display ();
120+ n = 0 ;
121+ }
122+ else
123+ {
124+ display.partialUpdate ();
125+ n++;
126+ }
127+ }
0 commit comments