#include <U8g2lib.h>
#include <Arduino.h>
#define SCREEN_I2C_ADDR 0x3C // or 0x3C
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RST_PIN -1 // Reset pin (-1 if not available)
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ OLED_RST_PIN);
const uint8_t* fonts[] = {
u8g2_font_ncenB08_tr,
u8g2_font_ncenB10_tr,
u8g2_font_ncenB12_tr,
u8g2_font_ncenB14_tr
};
const int numFonts = sizeof(fonts) / sizeof(fonts[0]);
void setup() {
u8g2.begin();
}
void loop() {
u8g2.clearBuffer(); // Clear the display buffer
u8g2.setFont(getRandomFont()); // Get a random font for displaying text
u8g2.drawStr(32, 30, "HARSH"); // Draw the name "HARSH" at (0, 10) coordinates
u8g2.sendBuffer(); // Send the buffer contents to the OLED display
delay(1000); // Wait for a short delay
}
const uint8_t* getRandomFont() {
int randomIndex = random(0, numFonts); // Generate a random index
return fonts[randomIndex]; // Return the font at the random index
}