main.py -- put your code here!

from pyb import OLED,delay import math

Create OLED Object

oled = OLED()

Clear OLED Cache

oled.fill(0)

Update OLED Display

oled.show()

Create Coordinate Variable

x = 0 y = 0

Function to calculate sine value

def calculate_sine(x): return int(16 * math.sin(math.radians(x)) + 16)

Function to calculate cosine value

def calculate_cosine(x): return int(16 * math.cos(math.radians(x)) + 16)

Flag to switch between sine and cosine curves

is_sine = True

while True: # Update OLED Content oled.fill(0)

if is_sine:
    y = calculate_sine(x)
else:
    y = calculate_cosine(x)

oled.pixel(x, y, 1)
oled.show()

x = x + 1
if x == 128:
    x = 0

delay(500

原文地址: http://www.cveoy.top/t/topic/hCaB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录