#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define OLED_RESET 4 // Pin reset OLED (jika ada)
#define SCREEN_WIDTH 128 // Lebar layar OLED
#define SCREEN_HEIGHT 64 // Tinggi layar OLED
// Definisikan pin SCL dan SDA
#define OLED_SCL 22
#define OLED_SDA 21
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Teks yang akan ditampilkan
const char* text1 = "Research and Development";
const char* text2 = "HOSPI NIAGA UTAMA";
// Panjang teks
int16_t textWidth1;
int16_t textWidth2;
// Posisi awal teks
int x1;
int x2;
// Kecepatan scrolling
const int scrollSpeed = 1;
void setup() {
Serial.begin(9600);
// Inisialisasi I2C dengan pin yang ditentukan
Wire.begin(OLED_SDA, OLED_SCL);
// Inisialisasi OLED
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Alamat I2C 0x3C (sesuaikan jika perlu)
display.clearDisplay();
display.display();
int16_t x, y; // variabel dummy untuk getTextBounds
uint16_t w, h; // variabel dummy untuk getTextBounds
// Hitung lebar teks
display.getTextBounds(text1, 0, 0, &x, &y, &w, &h);
textWidth1 = w;
display.getTextBounds(text2, 0, 0, &x, &y, &w, &h);
textWidth2 = w;
// Inisialisasi posisi awal teks (di luar layar sebelah kanan)
x1 = SCREEN_WIDTH;
x2 = SCREEN_WIDTH;
}
void loop() {
display.clearDisplay();
// Baris 1: Research and Development
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(x1, 10);
display.print(text1);
// Baris 2: HOSPI NIAGA UTAMA
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(x2, 30);
display.print(text2);
display.display();
// Update posisi teks
x1 -= scrollSpeed;
x2 -= scrollSpeed;
// Reset posisi teks jika sudah keluar layar
if (x1 < -textWidth1) {
x1 = SCREEN_WIDTH;
}
if (x2 < -textWidth2) {
x2 = SCREEN_WIDTH;
}
delay(20); // Delay untuk mengatur kecepatan scrolling (nilai ini bisa disesuaikan)
}