For the complete documentation index, see llms.txt. This page is also available as Markdown.

9. Advanced: OLED status card with a custom button badge

Difficulty: Advanced

oled-status-card-with-button-badge.gpc
const string ENABLED_TEXT = "ENABLED";
const string DISABLED_TEXT = "DISABLED";

int enabled;
int oled_dirty = TRUE;

main {
    if(event_press(PS5_TRIANGLE)) {
        enabled = !enabled;
        oled_dirty = TRUE;
    }

    if(oled_dirty) {
        draw_status_card();
        oled_dirty = FALSE;
    }
}

function draw_status_card() {
    cls_oled(OLED_BLACK);
    rect_oled(2, 2, 124, 60, FALSE, OLED_WHITE);

    // Draw a circular Triangle-button badge.
    circle_oled(15, 32, 9, TRUE, OLED_WHITE);
    putc_oled(1, ASCII_UPPER_T);
    puts_oled(12, 27, OLED_FONT_SMALL, 1, OLED_BLACK);

    if(enabled) {
        print(34, 23, OLED_FONT_SMALL, OLED_WHITE, addr(ENABLED_TEXT));
    } else {
        print(34, 23, OLED_FONT_SMALL, OLED_WHITE, addr(DISABLED_TEXT));
    }
    return 0;
}

What it teaches: dirty redraws, const strings, shape drawing, buffered characters, and a reusable OLED renderer. Adjust the badge letter or use supported special glyphs after device-testing the chosen font.

Last updated