from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf, sys
import utime
import math
pix_res_x = 128
pix_res_y = 64
def init_i2c(scl_pin, sda_pin):
# Initialize I2C device
i2c_dev = I2C(1, scl=Pin(scl_pin), sda=Pin(sda_pin), freq=200000)
i2c_addr = [hex(ii) for ii in i2c_dev.scan()]
if not i2c_addr:
print('No I2C Display Found')
sys.exit()
else:
print("I2C Address : {}".format(i2c_addr[0]))
print("I2C Configuration: {}".format(i2c_dev))
return i2c_dev
def display_pattern(oled):
oled.fill(0)
center_x, center_y = oled.width // 2, oled.height // 2 # Center of the display
num_points = 125 # no. of points
spacing = 150 # spacing
for i in range(num_points):
angle = i * 0.25 # angle
radius = i * spacing / num_points # Incremental radius
# coordinates
x = int(center_x + radius * math.cos(angle))
y = int(center_y + radius * math.sin(angle))
if 0 <= x < oled.width and 0 <= y < oled.height:
oled.pixel(x, y, 1)
oled.show() # Update the display
def main():
i2c_dev = init_i2c(scl_pin=27, sda_pin=26)
oled = SSD1306_I2C(pix_res_x, pix_res_y, i2c_dev)
display_pattern(oled)
if __name__ == '__main__':
main()