Test terminal-like printing in the text test

This commit is contained in:
Jeff Epler 2025-02-19 14:21:51 -06:00
parent 24d8426b8f
commit b4280411cc

View file

@ -1,42 +1,49 @@
// 16-bit Adafruit_GFX-compatible framebuffer for RP2350 HSTX
// Text mode demo
// With apologies to Stanley Kubrick et al
#include <Adafruit_dvhstx.h>
// If your board definition has PIN_CKP and related defines, DVHSTX_PINOUT_DEFAULT is available
// If your board definition has PIN_CKP and related defines,
// DVHSTX_PINOUT_DEFAULT is available
DVHSTXText3 display(DVHSTX_PINOUT_DEFAULT);
// If you get the message "error: 'DVHSTX_PINOUT_DEFAULTx' was not declared" then you need to give
// the pins numbers explicitly, like the example below. The order is: {CKP, D0P, D1P, D2P}
// If you get the message "error: 'DVHSTX_PINOUT_DEFAULTx' was not declared"
// then you need to give the pins numbers explicitly, like the example below.
// The order is: {CKP, D0P, D1P, D2P}.
//
// DVHSTXText3 display({12, 14, 16, 18});
void setup() {
Serial.begin(115200);
while(!Serial);
// Serial.printf("Your lucky number is %d\n", random(91));
if (!display.begin()) { // Blink LED if insufficient RAM
pinMode(LED_BUILTIN, OUTPUT);
for (;;) digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
for (;;)
digitalWrite(LED_BUILTIN, (millis() / 500) & 1);
}
Serial.println("display initialized");
display.show_cursor();
display.print("display initialized\n\n\n\n\n");
}
const char message[] = "All work and no play makes Jack a dull boy\n";
int cx, cy, i;
void loop() {
const static uint8_t colors[] = {
TextColor::TEXT_RED, TextColor::TEXT_GREEN, TextColor::TEXT_BLUE, TextColor::TEXT_YELLOW, TextColor::TEXT_MAGENTA, TextColor::TEXT_CYAN, TextColor::TEXT_WHITE,
const static TextColor colors[] = {
TextColor::TEXT_RED, TextColor::TEXT_GREEN, TextColor::TEXT_BLUE,
TextColor::TEXT_YELLOW, TextColor::TEXT_MAGENTA, TextColor::TEXT_CYAN,
TextColor::TEXT_WHITE,
};
// Draw random lines
uint8_t attr = colors[random(std::size(colors))];
uint8_t ch = random(95) + 32;
display.writePixel(random(display.width()), random(display.height()), (attr << 8) | ch);
if (i++ == 100) {
i = 0;
if ((cx += 1) == display.width()) {
cx = 0;
cy += 1;
if(cy == display.height()) { cy = 0; }
if (i == 0) {
auto attr = colors[random(std::size(colors))];
for (int j = random(91 - sizeof(message)); j; j--)
display.write(' ');
display.set_color(attr);
}
display.set_cursor(cx, cy);
}
sleep_ms(1);
int ch = message[i++];
if (ch) {
display.write(ch);
} else
i = 0;
sleep_ms(32 + random(32));
}