from machine import Pin, I2C
import ssd1306
import time
# ESP32-C3 Pin assignment
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# Initialize OLED display
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
# Define slide switch pin
switch = Pin(5, Pin.IN, Pin.PULL_DOWN)
# Messages to display
messages = [
"Welcome to Wokwi!",
"This is an OLED test.",
"Slide switch ON.",
"Enjoy coding!"
]
# Function to display messages
def display_messages():
for message in messages:
oled.fill(0) # Clear the screen
oled.text(message, 10, 25) # Display message
oled.show()
time.sleep(1.5) # Delay for 1.5 seconds
while True:
if switch.value() == 1: # If the switch is turned ON
display_messages()