编写代码重新编译一个上一个是错误的Python显示应用编写程序在OLED屏上绘制正弦曲线。具体要求如下:1在OLED屏上绘制一条正弦曲线2使用K1和K2键控制在OLED屏上绘制正弦或余弦曲线3绘制动态正弦曲线。正弦曲线从右往左移动每500ms移动一次。例子:# mainpy -- put your code here!from pyb import OLEDdelay# Create OLED O
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 著作权归作者所有。请勿转载和采集!