Zum Hauptinhalt springen

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.

Select Board
Inkplate10_Grayscale.ino
#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 None

Creates 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

TypeNameDescription
uint8_tmodeDisplay mode, INKPLATE_1BIT or INKPLATE_3BIT.
display.begin()returns void

Initializes the display hardware. Call it once in `setup()` before you draw anything.

ReturnsNothing.

display.clearDisplay()returns void

Clears 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 void

Sends the frame buffer to the panel with a full refresh.

ReturnsNothing.

Parameters

TypeNameDescription
bool_leaveOnOptional. When true, the panel supply stays on after the refresh. Defaults to false.
display.setTextColor(uint16_t c, uint16_t bg)returns void

Sets the text color and, optionally, the background color drawn behind each character.

ReturnsNothing.

Parameters

TypeNameDescription
uint16_tcText color.
uint16_tbgBackground color. Leave it out for a transparent background.
display.setCursor(int16_t x, int16_t y)returns void

Sets the position where the next `print()` call starts writing text.

ReturnsNothing.

Parameters

TypeNameDescription
int16_txHorizontal position in pixels.
int16_tyVertical position in pixels.
display.setTextSize(uint8_t s)returns void

Sets the text size as a multiple of the default 5 × 7 pixel font.

ReturnsNothing.

Parameters

TypeNameDescription
uint8_tsMagnification factor. 1 is the default size.
display.print(text)returns size_t

Prints 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

TypeNameDescription
const char *textThe text to print.
display.fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)returns void

Draws a filled rectangle.

ReturnsNothing.

Parameters

TypeNameDescription
int16_txLeft edge in pixels.
int16_tyTop edge in pixels.
int16_twWidth in pixels.
int16_thHeight in pixels.
uint16_tcolorFill 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.