// Fancy (offscreen canvas) flicker-free example for PyPortal
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Fonts/FreeSerifBold18pt7b.h>
#define TFT_D0 34 // Data bit 0 pin (MUST be on PORT byte boundary)
#define TFT_WR 26 // Write-strobe pin (CCL-inverted timer output)
#define TFT_DC 10 // Data/command pin
#define TFT_CS 11 // Chip-select pin
#define TFT_RST 24 // Reset pin
#define TFT_RD 9 // Read-strobe pin
#define TFT_BACKLIGHT 25
// ILI9341 screen with 8-bit parallel interface:
Adafruit_ILI9341 display(tft8bitbus, TFT_D0, TFT_WR, TFT_DC, TFT_CS, TFT_RST,
TFT_RD);
GFXcanvas1 canvas(120, 30); // 1-bit, 120x30 pixels
void setup() {
pinMode(TFT_BACKLIGHT, OUTPUT); // PyPortal requires
digitalWrite(TFT_BACKLIGHT, HIGH); // turning on backlight
display.begin(); // Initialize and
display.fillScreen(0x0000); // clear display
canvas.setFont(&FreeSerifBold18pt7b); // Use custom font and
canvas.setTextWrap(false); // clip text to canvas
}
void loop(void) {
canvas.fillScreen(0); // Clear canvas (not display)
canvas.setCursor(0, 24); // Pos. is BASE LINE when using fonts!
canvas.print(millis()); // Print elapsed time in milliseconds
// Copy canvas to screen at upper-left corner. As written here,
// assumes a color LCD, hence the color values of 0xFFFF (white)
// for foreground, 0x0000 (black) for background. Mono OLED can
// use 1 and 0. BOTH colors must be specified to overwrite the
// prior screen contents there.
display.drawBitmap(0, 0, canvas.getBuffer(),
canvas.width(), canvas.height(), 0xFFFF, 0x0000);
}
Once more, using a 16-bit canvas instead. This example doesn’t make good use of
color in the canvas—it’s still just white text on a black background—and is mostly just
to show how the drawing syntax is a little different.
// Fancy (offscreen color canvas) flicker-free example for PyPortal
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Fonts/FreeSerifBold18pt7b.h>
#define TFT_D0 34 // Data bit 0 pin (MUST be on PORT byte boundary)
#define TFT_WR 26 // Write-strobe pin (CCL-inverted timer output)
#define TFT_DC 10 // Data/command pin
#define TFT_CS 11 // Chip-select pin
#define TFT_RST 24 // Reset pin
#define TFT_RD 9 // Read-strobe pin
#define TFT_BACKLIGHT 25
// ILI9341 screen with 8-bit parallel interface:
Adafruit_ILI9341 display(tft8bitbus, TFT_D0, TFT_WR, TFT_DC, TFT_CS, TFT_RST,
TFT_RD);
©Adafruit Industries Page 37 of 38