print("Hello,Students")
print("This program will display series of text on OLED screen")
print("Created by : your name on 7/4/2025")
#Import libraries/modules
from machine import Pin, SoftI2C
import framebuf # Tambah ni penting!
# OLED driver (Wokwi tak ada ssd1306.py)
class SSD1306_I2C(framebuf.FrameBuffer):
def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False):
self.width = width
self.height = height
self.i2c = i2c
self.addr = addr
self.buffer = bytearray(self.height * self.width // 8)
super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
self.init_display()
def write_cmd(self, cmd):
self.i2c.writeto(self.addr, bytearray([0x80, cmd]))
def init_display(self):
for cmd in (
0xAE, 0xA4, 0xD5, 0x80, 0xA8, 0x3F, 0xD3, 0x00, 0x40, 0x8D, 0x14, 0x20,
0x00, 0xA1, 0xC8, 0xDA, 0x12, 0x81, 0xCF, 0xD9, 0xF1, 0xDB, 0x40, 0xA6, 0xAF):
self.write_cmd(cmd)
self.fill(0)
self.show()
def show(self):
for page in range(0, self.height // 8):
self.write_cmd(0xB0 | page)
self.write_cmd(0x00)
self.write_cmd(0x10)
self.i2c.writeto(self.addr, bytearray([0x40]) + self.buffer)
#Pin Declaration
SCL_Pin = Pin(22, Pin.OUT)
SDA_Pin = Pin(21, Pin.OUT)
OLED_Pin = SoftI2C(scl=SCL_Pin, sda=SDA_Pin)
#Object Declaration
screen = SSD1306_I2C(width=128, height=64, i2c=OLED_Pin)
#Main Program
#OLED code color --> 1 is for RED, 0 is for BLUE
screen.fill(0)
screen.text("Hello guys", 10, 10, 1)
screen.text("Selamat hari", 10, 30, 1)
screen.text("raya", 15, 50, 1)
screen.show()