-
Notifications
You must be signed in to change notification settings - Fork 1.2k
u8logreference
kraus edited this page Apr 22, 2018
·
21 revisions
U8log is an extension to U8g2 and U8x8. It implements a text window with automatic vertical scrolling. Text is written to the current cursor position within the text window. The cursor position is modified by special character commands:
| Char | Decimal | Description |
|---|---|---|
\n |
10 | Goto first position of the next line. |
\r |
13 | Goto first position of the same line. |
\t |
9 | Jump to the next tab position. |
\f |
12 | Clear the screen and goto upper left corner. |
U8log can be used for:
- Output of boot/startup information
- Error logging
- Debugging
- Output of sensor values
Features:
- Vertical scolling
- All features of Arduino
Serial.printare supported - Automatic or manual display update
Implementation:
-
class U8G2LOGfor U8g2 -
class U8X8LOGfor U8x8 -
u8x8_tstruct with plain c API
For the automatic display update, connect the U8x8log object with the U8x8 object. No further access to U8x8 is required. Just print data to U8x8log. Refresh of the screen is handled by U8x8log automatically.
Steps are:
- Create U8x8 object
- Create U8x8log object
- Setup static memory for the text window
- U8x8.begin()
- U8x8log.begin(): This will connect to U8x8 and the static memory
- Use U8x8log to print to the display
// U8x8 constructor for your display
U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
// Create a U8x8log object
U8X8LOG u8x8log;
// Define the dimension of the U8x8log window
#define U8LOG_WIDTH 16
#define U8LOG_HEIGHT 8
// Allocate static memory for the U8x8log window
uint8_t u8log_buffer[U8LOG_WIDTH*U8LOG_HEIGHT];
void setup(void)
{
// Startup U8x8
u8x8.begin();
// Set a suitable font. This font will be used for U8x8log
u8x8.setFont(u8x8_font_chroma48medium8_r);
// Start U8x8log, connect to U8x8, set the dimension and assign the static memory
u8x8log.begin(u8x8, U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buffer);
// Set the U8x8log redraw mode
u8x8log.setRedrawMode(1); // 0: Update screen with newline, 1: Update screen for every char
}
void loop(void) {
// Print a number on the U8x8log window
// The display will be refreshed
u8x8log.print(millis());
// Print a new line, scroll the text window content if required
// Refresh the screen
u8x8log.print("\n");
delay(500);
}
