Zum Hauptinhalt springen

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.

Select Board
Inkplate10_Black_And_White.ino
#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 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.drawPixel(int16_t x, int16_t y, uint16_t color)returns void

Sets one pixel in the frame buffer.

ReturnsNothing.

Parameters

TypeNameDescription
int16_txHorizontal position in pixels.
int16_tyVertical position in pixels.
uint16_tcolorPixel 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 void

Draws a straight line between two points.

ReturnsNothing.

Parameters

TypeNameDescription
int16_tx0Start x position.
int16_ty0Start y position.
int16_tx1End x position.
int16_ty1End y position.
uint16_tcolorLine color.
display.drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)returns void

Draws a rectangle outline.

ReturnsNothing.

Parameters

TypeNameDescription
int16_txLeft edge in pixels.
int16_tyTop edge in pixels.
int16_twWidth in pixels.
int16_thHeight in pixels.
uint16_tcolorOutline color.
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.
display.drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)returns void

Draws a circle outline.

ReturnsNothing.

Parameters

TypeNameDescription
int16_tx0Center x position.
int16_ty0Center y position.
int16_trRadius in pixels.
uint16_tcolorOutline color.
display.fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)returns void

Draws a filled circle.

ReturnsNothing.

Parameters

TypeNameDescription
int16_tx0Center x position.
int16_ty0Center y position.
int16_trRadius in pixels.
uint16_tcolorFill 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.