#include <U8g2lib.h>

// globale Konstanten
constexpr byte BUFFERLENGTH {2};

// globale Objekte/ Variablen
using DisplayType = U8G2_SSD1306_128X64_NONAME_2_HW_I2C;
DisplayType u8g2(U8G2_R0);

char charBuffer[BUFFERLENGTH];
byte counter {0};

void setup() {
  u8g2.begin();
  u8g2.setFont(u8g2_font_logisoso42_tn);
}

void loop() {
  counter = (counter < 4) ? counter + 1 : 1;
  snprintf(charBuffer, BUFFERLENGTH, "%d", counter);
  // Berechne X Position für zentrierte Darstellung
  byte xPos {(u8g2.getDisplayWidth() - u8g2.getMaxCharWidth() * (BUFFERLENGTH - 1)) / 2};
  // Berechne Y Position für zentrierte Darstellung
  byte yPos {(u8g2.getDisplayHeight() + u8g2.getMaxCharHeight()) / 2};
  u8g2.firstPage();
  do {
    u8g2.drawStr(xPos, yPos, charBuffer);
  } while (u8g2.nextPage());
  delay(1000);
}