Skip to main content

Hello world

What this example shows​

Print Hello world! with every character in a different color. The loop steps through the color indexes 0 to 5 and skips 1 (white), so every letter stays visible on the white screen.

Example code​

"""Example showing how to display colorful text on the screen."""

from inkplate7spectra import Inkplate # Include the Inkplate module

inkplate = Inkplate() # Create an instance of the display
inkplate.begin() # Initialize the display

inkplate.set_text_size(2) # Scale up the font size

inkplate.set_cursor(180, 180) # Set the cursor from where the text will be written

hello_world = "Hello world!" # Declare the string we want to print

i = 0 # Declare the counter we will use to iterate through the colors

# Iterate through each character in the string
for char in hello_world:
# Change the color of every character
inkplate.set_text_color(i)
# Print a single character to the framebuffer
inkplate.print(char)
# Iterate the color counter
i = i + 1
if i == 1: # If the color is white, skip it
i = i + 1
elif i // 6 > 0: # If we displayed all 6 colors, return to the first one
i = 0

inkplate.display() # Display what is drawn to the buffer

Functions used​

Inkplate()returns Inkplate

Creates the display object from the inkplate7spectra module. It takes no arguments.

ReturnsThe display object.

inkplate.begin()returns bool

Sets up I2C, the GPIO expander, the RTC, the panel interface and a white frame buffer. Call it once.

ReturnsTrue.

inkplate.set_text_size(s)returns None

Sets the text scale factor for print().

ReturnsNothing.

inkplate.set_cursor(x, y)returns None

Sets where print() starts, in pixels from the top-left corner.

ReturnsNothing.

inkplate.set_text_color(c)returns None

Sets the text color: 0 black, 1 white, 2 yellow, 3 red, 4 blue, 5 green (Inkplate.BLACK to Inkplate.GREEN).

ReturnsNothing.

inkplate.print(text)returns None

Draws text at the cursor into the frame buffer and moves the cursor to the end of it.

ReturnsNothing.

inkplate.display(leave_on=False)returns None

Sends the frame buffer to the panel and refreshes it. With leave_on=True the panel stays powered after the refresh.

ReturnsNothing.

What to expect​

After the refresh, Hello world! appears at (180, 180) at twice the base size, its letters cycling through black, yellow, red, blue and green. Nothing is printed in the shell.

🔗Open the complete example

examples/inkplate7spectra/hello_world.py

→