Hello world
Was dieses Beispiel zeigt
Gibt Hello world! aus, wobei jedes Zeichen eine andere Farbe hat. Die Schleife durchläuft die Farbindizes 0 bis 5 und überspringt 1 (Weiß), sodass jeder Buchstabe auf dem weißen Bildschirm sichtbar bleibt.
Beispielcode
"""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
Verwendete Funktionen
Inkplate()returns InkplateErstellt das Display-Objekt aus dem Modul inkplate7spectra. Es nimmt keine Argumente entgegen.
ReturnsDas Display-Objekt.
inkplate.begin()returns boolRichtet I2C, den GPIO-Expander, die RTC, die Panel-Schnittstelle und einen weißen Framebuffer ein. Rufen Sie sie nur einmal auf.
ReturnsTrue.
inkplate.set_text_size(s)returns NoneLegt den Skalierungsfaktor des Textes für print() fest.
ReturnsNichts.
inkplate.set_cursor(x, y)returns NoneLegt fest, wo print() beginnt, in Pixeln von der oberen linken Ecke aus.
ReturnsNichts.
inkplate.set_text_color(c)returns NoneLegt die Textfarbe fest: 0 Schwarz, 1 Weiß, 2 Gelb, 3 Rot, 4 Blau, 5 Grün (Inkplate.BLACK bis Inkplate.GREEN).
ReturnsNichts.
inkplate.print(text)returns NoneZeichnet Text an der Cursorposition in den Framebuffer und setzt den Cursor ans Ende des Textes.
ReturnsNichts.
inkplate.display(leave_on=False)returns NoneSendet den Framebuffer an das Panel und aktualisiert es. Mit leave_on=True bleibt das Panel nach der Aktualisierung mit Strom versorgt.
ReturnsNichts.
Was Sie erwarten können
Nach dem Aktualisieren erscheint Hello world! bei (180, 180) in doppelter Basisgröße, die Buchstaben wechseln dabei zwischen Schwarz, Gelb, Rot, Blau und Grün. In der Shell wird nichts ausgegeben.
🔗Vollständiges Beispiel öffnen
examples/inkplate7spectra/hello_world.py