#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>// library yang diperlukan mengontrol oled
#define SCREEN_ADDRESS 0x3C //alamat layar oled
#define SCREEN_WIDTH 128 //lebar layar
#define SCREEN_HEIGHT 64 //tinggi layar
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);//membuat objek dari kelas adafruid_SSD1306
void setup() { //fungsi yang dieksekusi sekali saat program dijalankan
Serial.begin(9600); //menginisialisasi komunikasi serial
// initialize OLED with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(30, 20); // set position to display
oled.println("Selamat Hari Raya Idul Fitri"); // set text
oled.display(); // display on OLED
}
void loop() {
for (int x = 0; x < 128; x++){
if(x>=65){
x=0;
}
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(x, 20);
oled.println("Hello World");
oled.display();
delay(100);
}
}