from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import math
# Initialize I2C communication
i2cbus = I2C(1, scl=Pin(7), sda=Pin(6))
# Initialize OLED display
oled = SSD1306_I2C(128, 64, i2cbus)
# Clear the display
oled.fill(0)
# Draw a rectangle centered at (96, 32) with width 30 and height 20
oled.rect(81, 22, 30, 20, 1) # Rectangle from (81, 22) to (111, 42)
# Draw a flipped triangle centered at (64, 32)
# Top point at (64, 22)
# Bottom-left point at (49, 42)
# Bottom-right point at (79, 42)
oled.line(49, 42, 79, 42, 1) # Bottom line from (49,42) to (79,42)
oled.line(79, 42, 64, 22, 1) # Right side from (79,42) to (64,22)
oled.line(64, 22, 49, 42, 1) # Left side from (64,22) to (49,42)
# Draw a circle centered at (32, 32) with a radius of 15
for X in range(128):
for Y in range(64):
if abs(math.sqrt((X - 32)**2 + (Y - 32)**2) - 15) <= 0.5:
oled.pixel(X, Y, 1)
# Show the display
oled.show()