|
| 1 | +/* |
| 2 | + Inkplate6COLOR_Read_Touchpads example for Soldered Inkplate6COLOR |
| 3 | + For this example you will need only a micro USB cable and Inkplate6COLOR. |
| 4 | + Select "e-radionica Inkplate6COLOR" or "Soldered Inkplate6COLOR" from Tools -> Board menu. |
| 5 | + Don't have "e-radionica Inkplate6COLOR" or "Soldered Inkplate6COLOR" option? Follow our tutorial and add it: |
| 6 | + https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/ |
| 7 | +
|
| 8 | + This example will show you how you can use the built-in touchpads (on PCB marked with numbers 1, 2 and 3). |
| 9 | + These are basically touch sensitive switches. You can read state each of these with function readTouchpad() |
| 10 | + and the argument you need to pass to this function is PAD1 if you want to read the state of touchpad marked |
| 11 | + as "1" on PCB, PAD2 for second touchpad, PAD3 for third. You can also use numbers as arguments. |
| 12 | + For that you need to pass number 0 for touchpad that is marked as 1 on the PCB, 1 for the second touchpad and 2 for |
| 13 | + the third. The function readTouchpad() will return 1 if selected touchpad is pressed, zero if not. |
| 14 | +
|
| 15 | + In this example, if you touch the first pad, it will decrese the number printed on serial, if you touch the third |
| 16 | + touch pad, it will increase the number, if you touch second touchpad, it will reset the number to zero. |
| 17 | +
|
| 18 | + NOTE: You can not use touch pads when an enclosure is fitted on the Inkplate - they are not that sensitive! |
| 19 | +
|
| 20 | + Want to learn more about Inkplate? Visit www.inkplate.io |
| 21 | + Looking to get support? Write on our forums: https://forum.soldered.com/ |
| 22 | + 6 June 2023 by Soldered |
| 23 | +*/ |
| 24 | + |
| 25 | +// Next 3 lines are a precaution, you can ignore those, and the example would also work without them |
| 26 | +#ifndef ARDUINO_INKPLATECOLOR |
| 27 | +#error "Wrong board selection for this example, please select Soldered Inkplate 6COLOR in the boards menu." |
| 28 | +#endif |
| 29 | + |
| 30 | +#include "Inkplate.h" // Include Inkplate library to the sketch |
| 31 | +Inkplate display; // Create an object on Inkplate library |
| 32 | + |
| 33 | +int number = 0; // Variable that stores our number |
| 34 | +int n = 0; // Variable that keeps track on how many times display is partially updated |
| 35 | + |
| 36 | +void setup() |
| 37 | +{ |
| 38 | + Serial.begin(115200); // Start serial to print the number |
| 39 | + display.begin(); // Init Inkplate library (you should call this function ONLY ONCE) |
| 40 | + display.clearDisplay(); // Clear frame buffer of display |
| 41 | + |
| 42 | + // Display text |
| 43 | + display.setCursor(100, 212); |
| 44 | + display.setTextColor(INKPLATE_RED); |
| 45 | + display.setTextSize(2); |
| 46 | + display.print("Open Serial monitor at 115200 baud!"); |
| 47 | + display.display(); |
| 48 | +} |
| 49 | + |
| 50 | +void loop() |
| 51 | +{ |
| 52 | + |
| 53 | + if (display.readTouchpad(PAD1)) |
| 54 | + { // Check if first pad has been touched. If it is, decrement the number and print to serial |
| 55 | + number--; |
| 56 | + Serial.print("The number is: "); |
| 57 | + Serial.println(number); |
| 58 | + } |
| 59 | + |
| 60 | + if (display.readTouchpad(PAD2)) |
| 61 | + { // If you touched second touchpad, set number to zero and print to serial |
| 62 | + number = 0; |
| 63 | + Serial.print("The number is: "); |
| 64 | + Serial.println(number); |
| 65 | + } |
| 66 | + |
| 67 | + if (display.readTouchpad(PAD3)) |
| 68 | + { // If you touched third touchpad, incerement the number and print to serial |
| 69 | + number++; |
| 70 | + Serial.print("The number is: "); |
| 71 | + Serial.println(number); |
| 72 | + } |
| 73 | + delay(100); // Wait a little bit between readings. |
| 74 | +} |
0 commit comments