Skip to content

Commit b64a74d

Browse files
authored
Merge pull request #292 from SolderedElectronics/touchpad-class
Add Touchpad class implementation for older Inkplate boards
2 parents f51c16c + 0b0d59f commit b64a74d

File tree

12 files changed

+304
-12
lines changed

12 files changed

+304
-12
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Inkplate10_Read_Touchpads example for Soldered Inkplate 10
3+
For this example you will need only a micro USB cable and Inkplate 10.
4+
Select "e-radionica Inkplate10" or "Soldered Inkplate10" from Tools -> Board menu.
5+
Don't have "e-radionica Inkplate10" or "Soldered Inkplate10" 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 touchpad.read( and the argument you need to pass to this function is PAD1 if you want to read the state of touchpad marked
10+
as "1" on PCB, PAD2 for second touchpad, PAD3 for third. You can also use numbers as arguments.
11+
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 the third.
12+
The function touchpad.read(ill return 1 if selected touchpad is pressed, zero if not.
13+
14+
In this example, if you touch the first pad, it will decrese number showed on screen, if you touch the third touch pad,
15+
it will increase the number, if you touch second touchpad, it will reset the number to zero.
16+
17+
NOTE: You can not use touch pads when an enclosure is fitted on the Inkplate - they are not that sensitive!
18+
19+
Want to learn more about Inkplate? Visit www.inkplate.io
20+
Looking to get support? Write on our forums: https://forum.soldered.com/
21+
11 February 2021 by Soldered
22+
*/
23+
24+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
25+
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
26+
#error "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu."
27+
#endif
28+
29+
#include "Inkplate.h" //Include Inkplate library to the sketch
30+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
31+
32+
int number = 0; // Variable that stores our number
33+
int n = 0; // Variable that keeps track on how many times display is partially updated
34+
35+
void setup()
36+
{
37+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
38+
display.clearDisplay(); // Clear frame buffer of display
39+
display.display(); // Put clear image on display
40+
display.setTextSize(5); // Set text scaling to five (text will be five times bigger)
41+
display.setTextColor(BLACK, WHITE); // Set text color to black and background color to white
42+
displayNumber(); // Call our function to display nubmer on screen
43+
}
44+
45+
void loop()
46+
{
47+
if (display.touchpad.read(1))
48+
{ // Check if first pad has been touched. If it is, decrement the number and refresh the screen.
49+
number--;
50+
displayNumber();
51+
}
52+
53+
if (display.touchpad.read(2))
54+
{ // If you touched second touchpad, set number to zero and refresh screen by calling our displayNumber() function
55+
number = 0;
56+
displayNumber();
57+
}
58+
59+
if (display.touchpad.read(3))
60+
{ // If you touched third touchpad, incerement the number and refresh the screen.
61+
number++;
62+
displayNumber();
63+
}
64+
delay(100); // Wait a little bit between readings.
65+
}
66+
67+
// Function that will write you number to screen
68+
void displayNumber()
69+
{
70+
display.clearDisplay(); // First, lets delete everything from frame buffer
71+
display.setCursor(580, 392); // Set print cursor at X=580, Y=392 (roughly in the middle of the screen)
72+
display.print(number, DEC); // Print the number
73+
display.setCursor(480, 790); // Set new print position (right above first touchpad)
74+
display.print('-'); // Print minus sign
75+
display.setCursor(580, 790); // Set new print position (right above second touchpad)
76+
display.print('0'); // Print zero
77+
display.setCursor(680, 790); // Set new print position (right above third touchpad)
78+
display.print('+'); // Print plus sign
79+
if (n > 20)
80+
{ // Chech if screen has been partially refreshed more than 20 times. If it is, do a full refresh. If is not, do a
81+
// partial refresh
82+
display.display();
83+
n = 0;
84+
}
85+
else
86+
{
87+
display.partialUpdate();
88+
n++;
89+
}
90+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Inkplate6_Read_Touchpads example for Soldered Inkplate 6
3+
For this example you will need only a micro USB cable and Inkplate 6.
4+
Select "e-radionica Inkplate6" or "Soldered Inkplate6" from Tools -> Board menu.
5+
Don't have "e-radionica Inkplate6" or "Soldered Inkplate6" 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 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 PCB, 1 for second touchpad and 2 for third.
13+
Function will return 1 if selected touchpad is pressed, zero if not.
14+
15+
In this example, if you touch first pad, ti will decrese number showed on screen, if you touch thirs touch pad,
16+
it will increase the number, if you touch second touchpad, it will reset number to zero.
17+
18+
Want to learn more about Inkplate? Visit www.inkplate.io
19+
Looking to get support? Write on our forums: https://forum.soldered.com/
20+
15 July 2020 by Soldered
21+
*/
22+
23+
24+
#include "Inkplate.h" //Include Inkplate library to the sketch
25+
Inkplate display(INKPLATE_1BIT); // Create an object on Inkplate library and also set library into 1 Bit mode (BW)
26+
27+
int number = 0; // Variable that stores our number
28+
int n = 0; // Variable that keeps track on how many times display is partially updated
29+
void setup()
30+
{
31+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
32+
display.clearDisplay(); // Clear frame buffer of display
33+
display.display(); // Put clear image on display
34+
display.setTextSize(5); // Set text scaling to five (text will be five times bigger)
35+
display.setTextColor(BLACK, WHITE); // Set text color to black and background color to white
36+
displayNumber(); // Call our function to display nubmer on screen
37+
}
38+
39+
void loop()
40+
{
41+
if (display.touchpad.read(1))
42+
{ // Check if first pad has been touched. If it is, decrement the number and refresh the screen.
43+
number--;
44+
displayNumber();
45+
}
46+
47+
if (display.touchpad.read(2))
48+
{ // If you touched second touchpad, set number to zero and refresh screen by calling our displayNumber() function
49+
number = 0;
50+
displayNumber();
51+
}
52+
53+
if (display.touchpad.read(3))
54+
{ // If you touched third touchpad, incerement the number and refresh the screen.
55+
number++;
56+
displayNumber();
57+
}
58+
delay(100); // Wait a little bit between readings.
59+
}
60+
61+
// Function that will write you number to screen
62+
void displayNumber()
63+
{
64+
display.clearDisplay(); // First, lets delete everything from frame buffer
65+
display.setCursor(385, 280); // Set print cursor at X=385, Y=280 (roughly in the middle of the screen)
66+
display.print(number, DEC); // Print the number
67+
display.setCursor(255, 560); // Set new print position (right above first touchpad)
68+
display.print('-'); // Print minus sign
69+
display.setCursor(385, 560); // Set new print position (right above second touchpad)
70+
display.print('0'); // Print zero
71+
display.setCursor(520, 560); // Set new print position (right above third touchpad)
72+
display.print('+'); // Print plus sign
73+
if (n > 20)
74+
{ // Chech if screen has been partially refreshed more than 20 times. If it is, do a full refresh. If is not, do a
75+
// partial refresh
76+
display.display();
77+
n = 0;
78+
}
79+
else
80+
{
81+
display.partialUpdate();
82+
n++;
83+
}
84+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Inkplate6_Read_Touchpads example for Soldered Inkplate 6COLOR
3+
For this example you will need only a micro USB cable and Inkplate 6COLOR.
4+
Select "e-radionica Inkplate6COLOR" or "Soldered Inkplate6COLOR" from Tools -> Board menu.
5+
Don't have "e-radionica Inkplate6" 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 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 touchpad.read()
10+
11+
12+
Want to learn more about Inkplate? Visit www.inkplate.io
13+
Looking to get support? Write on our forums: https://forum.soldered.com/
14+
15 July 2020 by Soldered
15+
*/
16+
17+
18+
#include "Inkplate.h" //Include Inkplate library to the sketch
19+
Inkplate display; // Create an object on Inkplate library
20+
21+
void setup()
22+
{
23+
Serial.begin(115200); // Init Serial documentation
24+
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
25+
}
26+
27+
void loop()
28+
{
29+
if (display.touchpad.read(1))
30+
{
31+
Serial.println("Pad 1 pressed!");
32+
}
33+
34+
if (display.touchpad.read(2))
35+
{
36+
Serial.println("Pad 2 pressed!");
37+
}
38+
39+
if (display.touchpad.read(3))
40+
{
41+
Serial.println("Pad 3 pressed!");
42+
}
43+
delay(100); // Wait a little bit between readings.
44+
}
45+

src/boards/Inkplate10/Inkplate10Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ void EPDDriver::gpioInit()
807807
internalIO.digitalWrite(11, LOW);
808808
internalIO.digitalWrite(12, LOW);
809809
#else
810+
// Initialize the touchpad class
811+
touchpad.begin(_inkplate);
810812
internalIO.pinMode(10, INPUT);
811813
internalIO.pinMode(11, INPUT);
812814
internalIO.pinMode(12, INPUT);

src/boards/Inkplate10/Inkplate10Driver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class EPDDriver
6363

6464
RTC rtc;
6565

66+
#ifdef ARDUINO_INKPLATE10
67+
Touchpad touchpad;
68+
#endif
69+
6670
Image image;
6771

6872
uint8_t _beginDone = 0;

src/boards/Inkplate6/Inkplate6Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ int EPDDriver::initDriver(Inkplate *_inkplatePtr)
119119
internalIO.pinMode(GMOD, OUTPUT, true);
120120
internalIO.pinMode(SPV, OUTPUT, true);
121121

122-
#ifndef ARDUINO_INKPLATE6V2
122+
#ifdef ARDUINO_INKPLATE6
123+
touchpad.begin(_inkplate);
123124
internalIO.pinMode(10, INPUT);
124125
internalIO.pinMode(11, INPUT);
125126
internalIO.pinMode(12, INPUT);

src/boards/Inkplate6/Inkplate6Driver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class EPDDriver : public Esp
6363
IOExpander internalIO;
6464
IOExpander externalIO;
6565

66+
#ifdef ARDUINO_INKPLATE6
67+
Touchpad touchpad;
68+
#endif
69+
6670
RTC rtc;
6771

6872
Image image;

src/boards/Inkplate6COLOR/Inkplate6COLORDriver.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,9 @@ void EPDDriver::setIOExpanderForLowPower()
395395
internalIO.begin(IO_INT_ADDR);
396396

397397
// TOUCHPAD PINS
398-
internalIO.pinMode(IO_PIN_B2, OUTPUT);
399-
internalIO.pinMode(IO_PIN_B3, OUTPUT);
400-
internalIO.pinMode(IO_PIN_B4, OUTPUT);
401-
402-
internalIO.digitalWrite(IO_PIN_B2, LOW);
403-
internalIO.digitalWrite(IO_PIN_B3, LOW);
404-
internalIO.digitalWrite(IO_PIN_B4, LOW);
398+
internalIO.pinMode(IO_PIN_B2, INPUT);
399+
internalIO.pinMode(IO_PIN_B3, INPUT);
400+
internalIO.pinMode(IO_PIN_B4, INPUT);
405401

406402
// Battery voltage Switch MOSFET
407403
internalIO.pinMode(IO_PIN_B1, OUTPUT);

src/boards/Inkplate6COLOR/Inkplate6COLORDriver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class EPDDriver
5555

5656
RTC rtc;
5757

58+
Touchpad touchpad;
59+
5860
ImageColor image;
5961

6062
uint8_t _beginDone = 0;

src/features/featureSelect.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef _FEATURE_SELECT_H
22
#define _FEATURE_SELECT_H
33

4-
#ifdef ARDUINO_INKPLATE10V2
4+
#if defined(ARDUINO_INKPLATE6V2) || defined(ARDUINO_INKPLATE5V2) || defined(ARDUINO_INKPLATE13SPECTRA) || \
5+
defined(ARDUINO_INKPLATE5) || defined(ARDUINO_INKPLATE10V2)
56
#include "SdFat/SdFat.h"
67
#include "rtc/rtc.h"
7-
#elif defined(ARDUINO_INKPLATE6V2) || defined(ARDUINO_INKPLATE5V2) || defined(ARDUINO_INKPLATECOLOR) || \
8-
defined(ARDUINO_INKPLATE13SPECTRA) || defined(ARDUINO_INKPLATE6) || defined(ARDUINO_INKPLATE10) || \
9-
defined(ARDUINO_INKPLATE5)
8+
#elif defined(ARDUINO_INKPLATECOLOR) || defined(ARDUINO_INKPLATE6) || defined(ARDUINO_INKPLATE10)
109
#include "SdFat/SdFat.h"
1110
#include "rtc/rtc.h"
11+
#include "touchpad/touchpad.h"
1212
#elif defined(ARDUINO_INKPLATE6FLICK)
1313
#include "SdFat/SdFat.h"
1414
#include "rtc/rtc.h"

0 commit comments

Comments
 (0)