Drawing graphics
What this example shows
Drawing pixels, lines, rectangles, circles and text on the 1200 × 825 panel in black and white mode. The library example steps through many more shapes, including thick lines, rounded rectangles, ellipses and polygons, and waits five seconds between screens because refreshing an e-paper screen more often than that is not recommended.
Example code
This listing is an excerpt of loop() from the library example, trimmed to a few shapes in a standalone sketch. Open the source link for the full demo, which also needs the logo.h file from the same folder.
#include "Inkplate.h"
Inkplate display(INKPLATE_1BIT); // Black and white mode
#define DELAY_MS 5000 // Refreshing e-paper more often than every 5 s is not recommended
void setup()
{
display.begin(); // Init library (call this ONLY ONCE)
display.clearDisplay(); // Clear the frame buffer (not the screen)
display.display(); // Show the clear frame buffer
}
void loop()
{
// Draw a pixel at x = 100, y = 50. Colors are BLACK or WHITE in this mode
display.clearDisplay();
display.drawPixel(100, 50, BLACK);
display.display();
delay(DELAY_MS);
// Draw two diagonal lines across the screen
display.clearDisplay();
display.drawLine(0, 0, 1199, 824, BLACK);
display.drawLine(1199, 0, 0, 824, BLACK);
display.display();
delay(DELAY_MS);
// Draw a rectangle outline and a filled rectangle
display.clearDisplay();
display.drawRect(300, 300, 400, 412, BLACK);
display.fillRect(100, 100, 150, 100, BLACK);
display.display();
delay(DELAY_MS);
// Draw a circle outline and a filled circle
display.clearDisplay();
display.drawCircle(400, 412, 75, BLACK);
display.fillCircle(600, 412, 75, BLACK);
display.display();
delay(DELAY_MS);
}
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.drawPixel(int16_t x, int16_t y, uint16_t color)returns voidSets one pixel in the frame buffer.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x | Horizontal position in pixels. |
int16_t | y | Vertical position in pixels. |
uint16_t | color | Pixel color. BLACK or WHITE in 1-bit mode, 0 to 7 in 3-bit mode. |
display.drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)returns voidDraws a straight line between two points.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x0 | Start x position. |
int16_t | y0 | Start y position. |
int16_t | x1 | End x position. |
int16_t | y1 | End y position. |
uint16_t | color | Line color. |
display.drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)returns voidDraws a rectangle outline.
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 | Outline color. |
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. |
display.drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)returns voidDraws a circle outline.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x0 | Center x position. |
int16_t | y0 | Center y position. |
int16_t | r | Radius in pixels. |
uint16_t | color | Outline color. |
display.fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)returns voidDraws a filled circle.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int16_t | x0 | Center x position. |
int16_t | y0 | Center y position. |
int16_t | r | Radius in pixels. |
uint16_t | color | Fill color. |
What to expect
The panel cycles through four screens, five seconds apart: a single pixel, two crossing diagonal lines, a rectangle outline with a filled rectangle, and a circle outline with a filled circle. The full library example prints nothing to the Serial Monitor.
The drawing functions come from the Adafruit GFX library that Inkplate builds on, so GFX tutorials apply to Inkplate 10 as well. In 3-bit mode the same functions take a color from 0 (black) to 7 (white), which the next page shows.