### Build and Install FreeType Library Source: https://github.com/adafruit/adafruit-gfx-library/blob/master/fontconvert/fontconvert_win.md Configure, build, and install the FreeType library using the MSYS command prompt. This prepares the library for use by other applications. ```bash ./configure --prefix=/mingw make make install ``` -------------------------------- ### Get Display Dimensions and Rotation Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Retrieve the current width, height, and rotation setting of the display. These functions account for the current rotation, providing accurate dimensions for drawing. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.setRotation(1); // Landscape mode tft.fillScreen(ILI9341_BLACK); // Get display info int16_t w = tft.width(); // Current width (rotation-aware) int16_t h = tft.height(); // Current height (rotation-aware) uint8_t r = tft.getRotation(); // Current rotation (0-3) tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2); tft.setCursor(10, 10); tft.print("Display: "); tft.print(w); tft.print(" x "); tft.println(h); tft.print("Rotation: "); tft.println(r); // Draw border using dimensions tft.drawRect(0, 0, w, h, ILI9341_YELLOW); // Draw center crosshairs tft.drawFastHLine(0, h / 2, w, ILI9341_RED); tft.drawFastVLine(w / 2, 0, h, ILI9341_RED); } void loop() {} ``` -------------------------------- ### Get Text Bounding Box Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Calculates the bounding rectangle of a text string, useful for centering or erasing text. It returns the top-left corner coordinates (x1, y1) and the width (w) and height (h) of the text. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #include "Fonts/FreeSansBold12pt7b.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void drawCenteredText(const char* text, int y) { int16_t x1, y1; uint16_t w, h; // Get text bounds starting from position (0, y) tft.getTextBounds(text, 0, y, &x1, &y1, &w, &h); // Returns: x1, y1 = upper-left corner; w, h = width and height // Calculate centered X position int16_t centerX = (tft.width() - w) / 2; // Draw the text centered tft.setCursor(centerX, y); tft.print(text); // Optionally draw bounding box for visualization tft.drawRect(centerX + x1, y1, w, h, ILI9341_RED); } void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); tft.setFont(&FreeSansBold12pt7b); tft.setTextColor(ILI9341_WHITE); drawCenteredText("Centered Title", 40); drawCenteredText("Another Line", 80); drawCenteredText("GFX Library", 120); // Update text without flicker using bounds const char* oldText = "Old Value: 100"; const char* newText = "New Value: 200"; int16_t x1, y1; uint16_t w, h; tft.getTextBounds(oldText, 10, 200, &x1, &y1, &w, &h); tft.fillRect(x1, y1, w, h, ILI9341_BLACK); // Erase old text area tft.setCursor(10, 200); tft.print(newText); } void loop() {} ``` -------------------------------- ### Compile fontconvert.c Source: https://github.com/adafruit/adafruit-gfx-library/blob/master/fontconvert/fontconvert_win.md Navigate to the fontconvert directory and use 'make' to compile the fontconvert.c utility. This generates the fontconvert.exe executable. ```bash cd /c/adafruit_gfx_library\fontconvert make ``` -------------------------------- ### Draw Individual Pixels with Adafruit GFX Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Demonstrates drawing single pixels and creating a gradient pattern using `drawPixel`. Requires Adafruit_GFX and a display driver like Adafruit_ILI9341. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Draw individual pixels tft.drawPixel(100, 100, ILI9341_WHITE); // Single white pixel at (100, 100) tft.drawPixel(101, 100, ILI9341_RED); // Red pixel tft.drawPixel(102, 100, ILI9341_GREEN); // Green pixel tft.drawPixel(103, 100, ILI9341_BLUE); // Blue pixel // Create a gradient pattern with individual pixels for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { uint16_t color = tft.color565(x * 2, y * 2, (x + y)); tft.drawPixel(x + 50, y + 50, color); } } } void loop() {} ``` -------------------------------- ### Navigate to FreeType Directory Source: https://github.com/adafruit/adafruit-gfx-library/blob/master/fontconvert/fontconvert_win.md Use MSYS commands to navigate to the extracted FreeType directory. Ensure FreeType is extracted to C:\. ```bash cd /c cd ft27 ``` -------------------------------- ### width / height / getRotation Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Retrieve display dimensions and the current rotation setting. ```APIDOC ## width / height / getRotation ### Description Get display dimensions (accounting for rotation) and current rotation setting. ### Method int16_t width() int16_t height() uint8_t getRotation() ### Parameters This method does not take any parameters. ### Response - **width()**: Returns the current width of the display in pixels. - **height()**: Returns the current height of the display in pixels. - **getRotation()**: Returns the current rotation setting (0-3). ### Request Example ```cpp int16_t w = tft.width(); int16_t h = tft.height(); uint8_t r = tft.getRotation(); ``` ``` -------------------------------- ### Fill Screen with Color Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Fills the entire display with a specified color. Useful for clearing the screen or setting a background color. Supports predefined colors and custom RGB565 values. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); // Clear to black tft.fillScreen(ILI9341_BLACK); delay(500); // Fill with various colors tft.fillScreen(ILI9341_RED); delay(500); tft.fillScreen(ILI9341_GREEN); delay(500); tft.fillScreen(ILI9341_BLUE); delay(500); // Custom color using color565 tft.fillScreen(tft.color565(128, 0, 128)); // Purple } void loop() {} ``` -------------------------------- ### Draw Lines with Adafruit GFX Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Illustrates drawing diagonal lines and creating a starburst pattern using `drawLine`. This function uses Bresenham's algorithm and optimizes for horizontal/vertical lines. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Draw diagonal line from top-left to bottom-right tft.drawLine(0, 0, 239, 319, ILI9341_WHITE); // Draw diagonal line from top-right to bottom-left tft.drawLine(239, 0, 0, 319, ILI9341_YELLOW); // Draw a starburst pattern int centerX = 120, centerY = 160; for (int angle = 0; angle < 360; angle += 15) { float rad = angle * 3.14159 / 180.0; int endX = centerX + cos(rad) * 80; int endY = centerY + sin(rad) * 80; uint16_t color = tft.color565(angle % 256, (angle * 2) % 256, (angle * 3) % 256); tft.drawLine(centerX, centerY, endX, endY, color); } } void loop() {} ``` -------------------------------- ### Text Rendering API Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt APIs for positioning the text cursor and rendering text using the Arduino Print class inheritance. Works with the built-in 5x7 font or custom fonts. ```APIDOC ## setCursor / print / println ### Description Position the text cursor and render text using the Arduino Print class inheritance. Works with the built-in 5x7 font or custom fonts. ### Method `setCursor`, `print`, `println` ### Endpoint N/A (Class methods) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp tft.setCursor(0, 0); // Set cursor to top-left tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); // 1 = 6x8 pixels per character tft.println("Hello World!"); // Prints and moves to next line tft.setTextSize(2); // 2 = 12x16 pixels tft.println("Size 2"); tft.setTextSize(3); // 3 = 18x24 pixels tft.println("Size 3"); tft.setCursor(0, 150); tft.setTextColor(ILI9341_YELLOW, ILI9341_BLUE); // Foreground, Background tft.setTextSize(2); tft.println("With Background"); tft.setCursor(0, 200); tft.setTextColor(ILI9341_GREEN); tft.print("Integer: "); tft.println(12345); tft.print("Float: "); tft.println(3.14159, 2); // 2 decimal places tft.print("Hex: 0x"); tft.println(255, HEX); // Print as hexadecimal ``` ### Response None (This is a drawing function) #### Success Response (200) None #### Response Example None ``` ```APIDOC ## setTextSize ### Description Set text magnification level for both X and Y axes. Size 1 is the base 6x8 pixel font. ### Method `setTextSize` ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Uniform scaling (both X and Y) tft.setCursor(0, 0); tft.setTextSize(1); tft.println("Size 1 (6x8)"); tft.setTextSize(2); tft.println("Size 2 (12x16)"); tft.setTextSize(4); tft.println("Size 4"); // Non-uniform scaling (different X and Y) tft.setCursor(0, 180); tft.setTextSize(3, 1); // Wide text: 3x horizontal, 1x vertical tft.println("Wide Text"); tft.setTextSize(1, 3); // Tall text: 1x horizontal, 3x vertical tft.setCursor(0, 220); tft.println("Tall"); ``` ### Response None (This is a drawing function) #### Success Response (200) None #### Response Example None ``` ```APIDOC ## setTextColor ### Description Set foreground color and optional background color for text. When background equals foreground, background is transparent. ### Method `setTextColor` ### Endpoint N/A (Class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Transparent background (only foreground color set) tft.setCursor(10, 20); tft.setTextColor(ILI9341_WHITE); // White text, transparent bg tft.println("Transparent BG"); // Solid background (useful for updating text without flicker) tft.setCursor(10, 60); tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE); // Black on white tft.println("Solid Background"); // Various color combinations tft.setCursor(10, 100); tft.setTextColor(ILI9341_YELLOW, ILI9341_RED); tft.println("Yellow on Red"); tft.setCursor(10, 140); tft.setTextColor(ILI9341_CYAN, ILI9341_MAGENTA); tft.println("Cyan on Magenta"); ``` ### Response None (This is a drawing function) #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Adafruit_GFX_Button: Interactive Button UI Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Implement interactive buttons for touchscreens using Adafruit_GFX_Button. Requires a touch controller and GFX-compatible display. Buttons can be initialized by center or upper-left coordinates. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #include "Adafruit_STMPE610.h" // Touch controller #define TFT_CS 10 #define TFT_DC 9 #define STMPE_CS 8 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS); Adafruit_GFX_Button button1; Adafruit_GFX_Button button2; void setup() { Serial.begin(115200); tft.begin(); ts.begin(); tft.setRotation(1); tft.fillScreen(ILI9341_BLACK); // Initialize button (center coordinates version) button1.initButton(&tft, // GFX object pointer 160, 80, // Center X, Y 120, 50, // Width, Height ILI9341_WHITE, // Outline color ILI9341_BLUE, // Fill color ILI9341_WHITE, // Text color "START", // Label (max 9 chars) 2); // Text size // Initialize button (upper-left coordinates version) button2.initButtonUL(&tft, // GFX object pointer 100, 140, // Upper-left X, Y 120, 50, // Width, Height ILI9341_WHITE, // Outline color ILI9341_RED, // Fill color ILI9341_WHITE, // Text color "STOP", // Label 2, 2); // Text size X, Y // Draw buttons in normal state button1.drawButton(); // Draw normal button2.drawButton(); } void loop() { if (ts.touched()) { TS_Point p = ts.getPoint(); // Map touch coordinates to display coordinates int16_t x = map(p.x, 0, 4096, 0, tft.width()); int16_t y = map(p.y, 0, 4096, 0, tft.height()); // Check if touch is within button bounds if (button1.contains(x, y)) { button1.press(true); // Set pressed state } else { button1.press(false); } if (button2.contains(x, y)) { button2.press(true); } else { button2.press(false); } } else { button1.press(false); button2.press(false); } // Handle button state changes if (button1.justPressed()) { Serial.println("START pressed!"); button1.drawButton(true); // Draw inverted (pressed) } if (button1.justReleased()) { Serial.println("START released!"); button1.drawButton(); // Draw normal } if (button2.justPressed()) { Serial.println("STOP pressed!"); button2.drawButton(true); } if (button2.justReleased()) { Serial.println("STOP released!"); button2.drawButton(); } // Check current state if (button1.isPressed()) { // Button is currently held down } } ``` -------------------------------- ### Draw Fast Horizontal and Vertical Lines Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Shows the usage of `drawFastHLine` and `drawFastVLine` for optimized drawing of straight lines. These are faster than `drawLine` for their respective orientations. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Draw horizontal lines (much faster than drawLine for horizontal) for (int y = 0; y < 320; y += 10) { tft.drawFastHLine(0, y, 240, ILI9341_CYAN); // x, y, width, color } // Draw vertical lines for (int x = 0; x < 240; x += 10) { tft.drawFastVLine(x, 0, 320, ILI9341_MAGENTA); // x, y, height, color } // Create a grid pattern with specific dimensions int gridX = 20, gridY = 50; int gridWidth = 200, gridHeight = 200; int cellSize = 20; for (int x = gridX; x <= gridX + gridWidth; x += cellSize) { tft.drawFastVLine(x, gridY, gridHeight, ILI9341_WHITE); } for (int y = gridY; y <= gridY + gridHeight; y += cellSize) { tft.drawFastHLine(gridX, y, gridWidth, ILI9341_WHITE); } } void loop() {} ``` -------------------------------- ### Set Cursor and Render Text Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Positions the text cursor and renders text using Arduino Print class inheritance. Works with the built-in 5x7 font or custom fonts. Use `println` for automatic newline. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Basic text rendering tft.setCursor(0, 0); // Set cursor to top-left tft.setTextColor(ILI9341_WHITE); tft.setTextSize(1); // 1 = 6x8 pixels per character tft.println("Hello World!"); // Prints and moves to next line // Different text sizes tft.setTextSize(2); // 2 = 12x16 pixels tft.println("Size 2"); tft.setTextSize(3); // 3 = 18x24 pixels tft.println("Size 3"); // Text with background color tft.setCursor(0, 150); tft.setTextColor(ILI9341_YELLOW, ILI9341_BLUE); // Foreground, Background tft.setTextSize(2); tft.println("With Background"); // Print numbers and variables tft.setCursor(0, 200); tft.setTextColor(ILI9341_GREEN); tft.print("Integer: "); tft.println(12345); tft.print("Float: "); tft.println(3.14159, 2); // 2 decimal places tft.print("Hex: 0x"); tft.println(255, HEX); // Print as hexadecimal } void loop() {} ``` -------------------------------- ### Draw XBM Bitmaps Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Use drawXBitmap to display XBM format bitmaps, commonly exported from GIMP. The bit order is reversed compared to standard bitmaps. Requires Adafruit_GFX and a compatible display driver. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); // XBM format icon (exported from GIMP as .xbm) #define icon_width 16 #define icon_height 16 const unsigned char icon_bits[] PROGMEM = { 0x00, 0x00, 0xFE, 0x7F, 0x02, 0x40, 0xFA, 0x5F, 0x0A, 0x50, 0xEA, 0x57, 0x2A, 0x54, 0xAA, 0x55, 0xAA, 0x55, 0x2A, 0x54, 0xEA, 0x57, 0x0A, 0x50, 0xFA, 0x5F, 0x02, 0x40, 0xFE, 0x7F, 0x00, 0x00 }; void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Draw XBM bitmap tft.drawXBitmap(100, 100, icon_bits, icon_width, icon_height, ILI9341_WHITE); // Parameters: x, y, bitmap, width, height, color // Draw in different colors tft.drawXBitmap(50, 100, icon_bits, icon_width, icon_height, ILI9341_RED); tft.drawXBitmap(150, 100, icon_bits, icon_width, icon_height, ILI9341_GREEN); } void loop() {} ``` -------------------------------- ### Set Text Color (Foreground/Background) Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Sets the foreground and optional background color for text. When background equals foreground, the background is transparent. Useful for updating text without flicker. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_NAVY); tft.setTextSize(2); // Transparent background (only foreground color set) tft.setCursor(10, 20); tft.setTextColor(ILI9341_WHITE); // White text, transparent bg tft.println("Transparent BG"); // Solid background (useful for updating text without flicker) tft.setCursor(10, 60); tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE); // Black on white tft.println("Solid Background"); // Various color combinations tft.setCursor(10, 100); tft.setTextColor(ILI9341_YELLOW, ILI9341_RED); tft.println("Yellow on Red"); tft.setCursor(10, 140); tft.setTextColor(ILI9341_CYAN, ILI9341_MAGENTA); tft.println("Cyan on Magenta"); } void loop() {} ``` -------------------------------- ### Register Adafruit GFX Component with CMake Source: https://github.com/adafruit/adafruit-gfx-library/blob/master/CMakeLists.txt Configures the Adafruit GFX library as a component for the ESP-IDF build system. It specifies source files, include directories, and required dependencies. ```cmake cmake_minimum_required(VERSION 3.5) idf_component_register(SRCS "Adafruit_GFX.cpp" "Adafruit_GrayOLED.cpp" "Adafruit_SPITFT.cpp" "glcdfont.c" INCLUDE_DIRS "." REQUIRES arduino Adafruit_BusIO) project(Adafruit-GFX-Library) ``` -------------------------------- ### Draw and Fill Circles Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Use `drawCircle` for outlined circles and `fillCircle` for filled ones. Specify the center coordinates (x, y), radius, and color. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Simple outlined circle tft.drawCircle(60, 60, 40, ILI9341_WHITE); // centerX, centerY, radius, color // Filled circle tft.fillCircle(180, 60, 40, ILI9341_RED); // Concentric circles (target pattern) int targetX = 120, targetY = 200; tft.fillCircle(targetX, targetY, 60, ILI9341_RED); tft.fillCircle(targetX, targetY, 45, ILI9341_WHITE); tft.fillCircle(targetX, targetY, 30, ILI9341_RED); tft.fillCircle(targetX, targetY, 15, ILI9341_WHITE); tft.fillCircle(targetX, targetY, 5, ILI9341_RED); // Circle outline pattern for (int r = 10; r <= 50; r += 10) { tft.drawCircle(60, 200, r, ILI9341_CYAN); } } void loop() {} ``` -------------------------------- ### Draw and Fill Triangles Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Use drawTriangle and fillTriangle to draw triangles by specifying three vertex coordinates. Requires Adafruit_GFX and a compatible display driver. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Outlined triangle tft.drawTriangle(60, 10, 10, 80, 110, 80, ILI9341_WHITE); // Parameters: x0, y0, x1, y1, x2, y2, color // Filled triangle tft.fillTriangle(180, 10, 130, 80, 230, 80, ILI9341_RED); // Right-angle triangle tft.fillTriangle(10, 100, 10, 180, 100, 180, ILI9341_GREEN); // Arrow pointing right tft.fillTriangle(200, 140, 130, 100, 130, 180, ILI9341_YELLOW); // Sierpinski-style pattern (nested triangles) int baseY = 300; tft.fillTriangle(120, 200, 20, baseY, 220, baseY, ILI9341_BLUE); tft.fillTriangle(120, 200, 70, 250, 170, 250, ILI9341_BLACK); tft.fillTriangle(70, 250, 20, baseY, 120, baseY, ILI9341_BLACK); tft.fillTriangle(170, 250, 120, baseY, 220, baseY, ILI9341_BLACK); } void loop() {} ``` -------------------------------- ### Draw and Fill Rectangles Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Use `drawRect` for outlined rectangles and `fillRect` for filled ones. Specify the top-left corner (x, y), width, height, and color. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Draw outlined rectangle tft.drawRect(10, 10, 100, 50, ILI9341_WHITE); // x, y, width, height, color // Draw filled rectangle tft.fillRect(10, 70, 100, 50, ILI9341_RED); // Nested rectangles (concentric boxes) for (int i = 0; i < 10; i++) { int offset = i * 8; uint16_t color = tft.color565(i * 25, 0, 255 - i * 25); tft.drawRect(120 + offset, 10 + offset, 100 - offset * 2, 100 - offset * 2, color); } // Filled rectangles with transparency effect (layered) tft.fillRect(50, 150, 80, 80, ILI9341_RED); tft.fillRect(90, 190, 80, 80, ILI9341_GREEN); tft.fillRect(130, 150, 80, 80, ILI9341_BLUE); } void loop() {} ``` -------------------------------- ### drawRGBBitmap Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Draws 16-bit (RGB 5/6/5) color bitmaps for full-color images. ```APIDOC ## drawRGBBitmap ### Description Draws 16-bit (RGB 5/6/5) color bitmaps for full-color images. ### Method `drawRGBBitmap` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Small 4x4 RGB565 color bitmap in PROGMEM const uint16_t colorBitmap[] PROGMEM = { 0xF800, 0xF800, 0x07E0, 0x07E0, // Red, Red, Green, Green 0xF800, 0xF800, 0x07E0, 0x07E0, // Red, Red, Green, Green 0x001F, 0x001F, 0xFFFF, 0xFFFF, // Blue, Blue, White, White 0x001F, 0x001F, 0xFFFF, 0xFFFF // Blue, Blue, White, White }; tft.drawRGBBitmap(100, 100, colorBitmap, 4, 4); // Parameters: x, y, bitmap, width, height ``` ### Response None (This is a drawing function) #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Bitmap Drawing API Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Functions to draw monochrome bitmaps from PROGMEM or RAM. ```APIDOC ## drawBitmap ### Description Draw monochrome bitmaps from PROGMEM or RAM. Set bits are drawn in the foreground color, with optional background color for unset bits. ### Method `drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)` `drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t foreground, uint16_t background)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Draw bitmap with transparent background tft.drawBitmap(10, 10, smiley, 16, 16, ILI9341_YELLOW); // Draw bitmap with background color tft.drawBitmap(50, 10, smiley, 16, 16, ILI9341_YELLOW, ILI9341_BLUE); ``` ### Response #### Success Response (200) None (modifies the display buffer) #### Response Example None ``` ```APIDOC ## drawXBitmap ### Description Draw XBM format bitmaps exported from GIMP. The bit order is reversed compared to standard bitmaps (LSB to MSB). ### Method `drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Draw XBM bitmap tft.drawXBitmap(100, 100, icon_bits, icon_width, icon_height, ILI9341_WHITE); ``` ### Response #### Success Response (200) None (modifies the display buffer) #### Response Example None ``` -------------------------------- ### Draw and Fill Ellipses Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Use drawEllipse and fillEllipse to create oval shapes with independent horizontal and vertical radii. Requires Adafruit_GFX and a compatible display driver. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Wide ellipse (wider than tall) tft.drawEllipse(120, 60, 80, 30, ILI9341_WHITE); // centerX, centerY, radiusW, radiusH, color // Tall ellipse (taller than wide) tft.fillEllipse(120, 160, 30, 60, ILI9341_BLUE); // Create an oval face tft.fillEllipse(120, 240, 50, 65, ILI9341_YELLOW); // Face tft.fillEllipse(100, 220, 8, 12, ILI9341_BLACK); // Left eye tft.fillEllipse(140, 220, 8, 12, ILI9341_BLACK); // Right eye tft.drawEllipse(120, 260, 20, 10, ILI9341_BLACK); // Mouth // Concentric ellipses for (int i = 1; i <= 5; i++) { tft.drawEllipse(60, 160, i * 10, i * 15, tft.color565(i * 50, 0, 255 - i * 50)); } } void loop() {} ``` -------------------------------- ### Set Custom GFX Font Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Applies a custom font or reverts to the default 5x7 font. Custom fonts offer proportional spacing. Pass NULL or call without arguments to use the built-in font. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #include "Fonts/FreeSans9pt7b.h" #include "Fonts/FreeSansBold12pt7b.h" #include "Fonts/FreeSerif18pt7b.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); tft.setTextColor(ILI9341_WHITE); // Built-in font (pass NULL to revert) tft.setFont(); // or tft.setFont(NULL); tft.setCursor(10, 20); tft.println("Built-in 5x7 font"); // FreeSans 9pt font tft.setFont(&FreeSans9pt7b); tft.setCursor(10, 60); // Note: custom fonts use baseline positioning tft.println("FreeSans 9pt"); // FreeSansBold 12pt font tft.setFont(&FreeSansBold12pt7b); tft.setCursor(10, 100); tft.println("FreeSansBold 12pt"); // FreeSerif 18pt font tft.setFont(&FreeSerif18pt7b); tft.setCursor(10, 160); tft.println("Serif 18pt"); // Revert to built-in font tft.setFont(); tft.setCursor(10, 200); tft.println("Back to built-in"); } void loop() {} ``` -------------------------------- ### Configure Makefile for fontconvert.c Source: https://github.com/adafruit/adafruit-gfx-library/blob/master/fontconvert/fontconvert_win.md Modify the Makefile for fontconvert.c to include the FreeType library path and compiler flags. This ensures the utility can find and link against the FreeType library during compilation. ```makefile all: fontconvert CC = gcc CFLAGS = -Wall -I c:/mingw/include/freetype2 LIBS = -lfreetype fontconvert: fontconvert.c $(CC) $(CFLAGS) $< $(LIBS) -o $@ clean: rm -f fontconvert ``` -------------------------------- ### Draw RGB Bitmap Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Draws 16-bit (RGB 5/6/5) color bitmaps. Supports both PROGMEM and RAM-allocated bitmaps. Ensure correct color format and dimensions are provided. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); // Small 4x4 RGB565 color bitmap in PROGMEM const uint16_t colorBitmap[] PROGMEM = { 0xF800, 0xF800, 0x07E0, 0x07E0, // Red, Red, Green, Green 0xF800, 0xF800, 0x07E0, 0x07E0, // Red, Red, Green, Green 0x001F, 0x001F, 0xFFFF, 0xFFFF, // Blue, Blue, White, White 0x001F, 0x001F, 0xFFFF, 0xFFFF // Blue, Blue, White, White }; void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Draw small RGB bitmap tft.drawRGBBitmap(100, 100, colorBitmap, 4, 4); // Parameters: x, y, bitmap, width, height // Generate and draw a gradient bitmap in RAM uint16_t gradientBitmap[32 * 32]; for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { gradientBitmap[y * 32 + x] = tft.color565(x * 8, y * 8, 128); } } tft.drawRGBBitmap(50, 50, gradientBitmap, 32, 32); } void loop() {} ``` -------------------------------- ### Display Control Functions Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Functions for controlling the overall display appearance. ```APIDOC ## fillScreen ### Description Fill the entire display with a single color. Useful for clearing the screen or setting a background. ### Method `fillScreen(uint16_t color)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp tft.fillScreen(ILI9341_BLACK); ``` ### Response None ``` -------------------------------- ### Enable/Disable Text Wrapping Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Controls whether text automatically wraps to the next line when it reaches the display edge. Enabled by default. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2); // With wrapping enabled (default) tft.setCursor(0, 0); tft.setTextWrap(true); tft.println("This is a long line of text that will automatically wrap to the next line when it reaches the edge of the display."); // With wrapping disabled (text clips at edge) tft.setCursor(0, 150); tft.setTextWrap(false); tft.println("This long line will be clipped at the display edge and not wrap."); } void loop() {} ``` -------------------------------- ### Draw Monochrome Bitmaps Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Use drawBitmap to display monochrome bitmaps from PROGMEM or RAM. Unset bits can be transparent or drawn with a specified background color. Requires Adafruit_GFX and a compatible display driver. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); // 16x16 smiley face bitmap stored in PROGMEM const unsigned char smiley[] PROGMEM = { 0x03, 0xC0, // ......####...... 0x0F, 0xF0, // ....########.... 0x1F, 0xF8, // ...##########... 0x3F, 0xFC, // ..############.. 0x71, 0x8E, // .###..##..###. 0x71, 0x8E, // .###..##..###. 0xFF, 0xFF, // ################ 0xFF, 0xFF, // ################ 0xFF, 0xFF, // ################ 0xE1, 0x87, // ###....##....### 0xF1, 0x8F, // ####...##...#### 0x78, 0x1E, // .####......####. 0x3F, 0xFC, // ..############.. 0x1F, 0xF8, // ...##########... 0x0F, 0xF0, // ....########.... 0x03, 0xC0 // ......####...... }; void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Draw bitmap with transparent background (unset bits not drawn) tft.drawBitmap(10, 10, smiley, 16, 16, ILI9341_YELLOW); // Parameters: x, y, bitmap, width, height, color // Draw bitmap with background color (unset bits drawn in bg color) tft.drawBitmap(50, 10, smiley, 16, 16, ILI9341_YELLOW, ILI9341_BLUE); // Parameters: x, y, bitmap, width, height, foreground, background // Draw multiple copies at different scales using loops for (int i = 0; i < 5; i++) { tft.drawBitmap(10 + i * 40, 50, smiley, 16, 16, tft.color565(255 - i * 40, i * 50, 128)); } } void loop() {} ``` -------------------------------- ### Draw and Fill Rounded Rectangles Source: https://context7.com/adafruit/adafruit-gfx-library/llms.txt Use `drawRoundRect` and `fillRoundRect` for rectangles with rounded corners. The fifth parameter specifies the corner radius. ```cpp #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h" #define TFT_CS 10 #define TFT_DC 9 Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); void setup() { tft.begin(); tft.fillScreen(ILI9341_BLACK); // Outlined rounded rectangle tft.drawRoundRect(10, 10, 100, 60, 10, ILI9341_WHITE); // x, y, w, h, radius, color // Filled rounded rectangle (button-like appearance) tft.fillRoundRect(10, 80, 100, 60, 15, ILI9341_BLUE); tft.drawRoundRect(10, 80, 100, 60, 15, ILI9341_WHITE); // Add border // Various corner radii demonstration tft.fillRoundRect(130, 10, 80, 40, 5, ILI9341_RED); // Small radius tft.fillRoundRect(130, 60, 80, 40, 15, ILI9341_GREEN); // Medium radius tft.fillRoundRect(130, 110, 80, 40, 20, ILI9341_CYAN); // Large radius (pill shape) // Create a button-style UI element int btnX = 60, btnY = 200, btnW = 120, btnH = 50; tft.fillRoundRect(btnX, btnY, btnW, btnH, 10, ILI9341_DARKGREEN); tft.drawRoundRect(btnX, btnY, btnW, btnH, 10, ILI9341_WHITE); tft.setCursor(btnX + 30, btnY + 18); tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2); tft.print("OK"); } void loop() {} ```