Display modes: grayscale
What this example shows
Switching Inkplate 10 to 3-bit grayscale mode. Pixels then take 8 shades, where 0 is black, 7 is white and the values between are grays. The library example runs a long series of grayscale drawing demos. This page shows the part that matters most: creating the object in INKPLATE_3BIT and drawing with shades.
Example code
This listing is an excerpt of the library example, rewritten as a short standalone sketch. Open the source link for the full demo, which also needs the image.h file from the same folder.
#include "Inkplate.h"
Inkplate display(INKPLATE_3BIT); // Grayscale mode, 8 shades from 0 (black) to 7 (white)
void setup()
{
display.begin();
display.clearDisplay();
display.display();
display.setTextColor(0, 7); // Black text on a white background
display.setCursor(250, 420);
display.setTextSize(4);
display.print("Welcome to Inkplate 10!");
// Eight filled squares, one for each shade
for (int shade = 0; shade < 8; shade++)
{
display.fillRect(100 + shade * 130, 100, 120, 120, shade);
}
display.display();
}
void loop()
{
// Nothing...
}
Functions used
Inkplate(uint8_t mode)returns NoneCreates the Inkplate object. The mode decides how many bits describe each pixel: `INKPLATE_1BIT` for black and white, `INKPLATE_3BIT` for grayscale.
ReturnsConstructor; no return value.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | mode | Display mode, INKPLATE_1BIT or INKPLATE_3BIT. |
display.begin()returns voidInitializes the display hardware. Call it once in `setup()` before you draw anything.
ReturnsNothing.
display.clearDisplay()returns voidClears the frame buffer in the ESP32 memory. It does not change what the panel currently shows; call `display()` for that.
ReturnsNothing.
display.display(bool _leaveOn = 0)returns voidSends the frame buffer to the panel with a full refresh.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _leaveOn | Optional. When true, the panel supply stays on after the refresh. Defaults to false. |
display.setTextColor(uint16_t c, uint16_t bg)returns voidSets the text color and, optionally, the background color drawn behind each character.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
uint16_t | c | Text color. |
uint16_t | bg | Background color. Leave it out for a transparent background. |
display.setCursor(int16_t x, int16_t y)returns voidSets the position where the next `print()` call starts writing text.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x | Horizontal position in pixels. |
int16_t | y | Vertical position in pixels. |
display.setTextSize(uint8_t s)returns voidSets the text size as a multiple of the default 5 × 7 pixel font.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | s | Magnification factor. 1 is the default size. |
display.print(text)returns size_tPrints text at the cursor position. This is the standard Arduino `Print` function, which the library inherits through the Adafruit GFX base class.
ReturnsNumber of bytes printed.
Parameters
| Type | Name | Description |
|---|---|---|
const char * | text | The text to print. |
display.fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)returns voidDraws a filled rectangle.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x | Left edge in pixels. |
int16_t | y | Top edge in pixels. |
int16_t | w | Width in pixels. |
int16_t | h | Height in pixels. |
uint16_t | color | Fill color. |
What to expect
The panel shows a row of eight squares that run from black to white, with Welcome to Inkplate 10! below them. Partial updates are meant mainly for 1-bit mode, so use display() for the best result here.