#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <WiFi.h>
#define SCREEN_WIDTH 127
#define SCREEN_HEIGHT 63
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, OLED_RESET);
const char* ssid = "Wokwi-GUEST";
const char* password = "";
int loadingIndex = 20;
bool isUpdateble = false;
void setup() {
Serial.begin(115200);
Wire.begin(22, 23);
Wire1.begin(16, 17);
display1.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display2.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display1.clearDisplay();
display2.clearDisplay();
}
const uint8_t bitmap6[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x7f, 0xe0, 0x00, 0x70, 0xe0, 0x00, 0x60, 0x7f, 0xfc, 0x60, 0x3f, 0xfe, 0x60, 0x00, 0x0e, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x06, 0x60, 0x00, 0x0e, 0x7f, 0xff, 0xfe, 0x3f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const uint8_t bitmap7[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x3f, 0xfc, 0x00, 0xff, 0xfc, 0x00, 0xfc, 0x0c, 0x00, 0xc0, 0x0c, 0x00, 0xc0, 0x0c, 0x00, 0xc0, 0x0c, 0x00, 0xc0, 0x0c, 0x00, 0xc0, 0x0c, 0x00, 0xc0, 0x0c, 0x00, 0xc0, 0xfc, 0x00, 0xc1, 0xfc, 0x0f, 0xc3, 0x9c, 0x1f, 0xc3, 0x0c, 0x39, 0xc3, 0x0c, 0x30, 0xc3, 0x9c, 0x30, 0xc1, 0xf8, 0x39, 0xc0, 0xf0, 0x1f, 0x80, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int currentStart = 0; // Start index for scrolling
unsigned long lastScrollTime = 0; // Tracks last scroll update time
void oled_put_str(char x, char y, String str, int srl_len, int srl_dly) {
display2.setCursor(x, y);
if (str.length() <= srl_len) {
// If text fits, print it directly
display2.print(str);
} else {
// Add spaces at the end for smooth scrolling
String Str = str + " "; // 25 spaces + 1 extra
// Scroll only when enough time has passed
if (millis() - lastScrollTime >= srl_dly) {
lastScrollTime = millis(); // Update timestamp
// Print only a portion of the text based on currentStart
display2.setCursor(x, y);
display2.print(Str.substring(currentStart, currentStart + srl_len));
// Wrap around scrolling logic
currentStart = (currentStart + 1) % Str.length();
}
}
}
void updateDisplay() {
display2.clearDisplay();
display2.drawBitmap(0, 0, bitmap6, 24, 24, 1);
display2.drawBitmap(0, 25, bitmap7, 24, 24, 1);
display2.setCursor(29, 6);
display2.setTextSize(2);
display2.setTextColor(WHITE);
display2.print("Folder-1");
// display2.setCursor(29, 30);
oled_put_str(29, 30, "Hello, scrolling text!", 8, 50);
display2.drawRoundRect(2, 50, 90, 10, 3, 1);
display2.fillRoundRect(2, 50, 30, 10, 3, 1);
display2.setCursor(95, 51);
display2.setTextSize(1);
display2.print("00:00");
display2.display();
}
void loop() {
updateDisplay();
}