#include <Arduino.h>
#include <U8g2lib.h> // u8g2 library for drawing on OLED display - needs to be installed in Arduino IDE first
#include <Wire.h> // wire library for IIC communication with the OLED display
//U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0); // set the OLED display to 128x64px, HW IIC, no rotation, used in WOKWI
U8G2_SH1107_128X128_1_HW_I2C u8g2(U8G2_R0); // final display, 128x128px [page buffer, size = 128 bytes], HW IIC connection
// IIC connection of the OLED display and Arduino UNO
// +5V > +5V
// GND > GND
// SCL (serial clock) > A5 or SCL
// SDA (serial data) > A4 or SDA
int16_t offset = 128; // Initialize the offset for scrolling
void setup(void) {
u8g2.begin(); // begin the u8g2 library
u8g2.setContrast(255); // set display contrast/brightness
}
void loop(void) {
u8g2.firstPage(); // select the first page of the display (page is 128x8px), since we are using the page drawing method of the u8g2 library
do {
// Line 1 - using font u8g2_font_ncenB14_tr
u8g2.setFont(u8g2_font_ncenB14_tr); // set the u8g2 font
u8g2.drawStr(offset, 20, "Line 1: ARVIND"); // draw the string at (x, y)
// Line 2 - using font u8g2_font_helvB10_tr
u8g2.setFont(u8g2_font_helvB10_tr); // set the u8g2 font
u8g2.drawStr(offset + 150, 40, "Line 2: INDIA"); // draw the string at (x, y)
// Line 3 - using font u8g2_font_courB08_tr
u8g2.setFont(u8g2_font_courB08_tr); // set the u8g2 font
u8g2.drawStr(offset + 300, 60, "Line 3: Nandurbar"); // draw the string at (x, y)
// Line 4 - using font u8g2_font_6x10_tf
u8g2.setFont(u8g2_font_6x10_tf); // set the u8g2 font
u8g2.drawStr(offset + 450, 80, "Line 4: 7020336035"); // draw the string at (x, y)
// Line 5 - using font u8g2_font_ncenB14_tr
u8g2.setFont(u8g2_font_ncenB14_tr); // set the u8g2 font
u8g2.drawStr(offset + 600, 100, "Line 5: Example 1"); // draw the string at (x, y)
// Line 6 - using font u8g2_font_helvB10_tr
u8g2.setFont(u8g2_font_helvB10_tr); // set the u8g2 font
u8g2.drawStr(offset + 750, 120, "Line 6: Example 2"); // draw the string at (x, y)
} while (u8g2.nextPage()); // go over all the pages until the whole display is updated
// Decrease offset for scrolling effect
offset--;
if (offset < -900) { // Adjust this value based on the total width of the scrolling text
offset = 128; // Reset the offset after the text has scrolled off the display
}
delay(50); // Adjust the delay for scrolling speed
}
scrolling text on oled 19/07/24
https://wokwi.com/projects/398645500196353025