main.py -- put your code here!

from pyb import OLED, delay, Pin

Create OLED Object

oled = OLED()

Create Button Objects

k1 = Pin('K1', Pin.IN, Pin.PULL_UP) k2 = Pin('K2', Pin.IN, Pin.PULL_UP)

Clear OLED Cache

oled.fill(0)

Update OLED Display

oled.show()

Create Coordinate Variables

x = 8 y = 0

Create Variables for wave selection and movement

wave_type = 'sin' move_counter = 0

while True: # Update OLED Content oled.fill(0) if wave_type == 'sin': oled.text("Sin Wave", x, y, 1) elif wave_type == 'cos': oled.text("Cos Wave", x, y, 1) oled.show()

# Move wave every 500ms
if move_counter == 5:
    y += 1
    if y == 32:
        y = -8
    move_counter = 0

# Check button press to toggle wave type
if not k1.value():
    if wave_type == 'sin':
        wave_type = 'cos'
    else:
        wave_type = 'sin'
    delay(200)  # Delay to avoid multiple button press detection

# Check button press to exit program
if not k2.value():
    break

delay(100)
move_counter += 1

Clear OLED Cache

oled.fill(0) oled.show(

编写代码上一个代码编译的图像是不连续的重新编译Python显示应用编写程序在OLED屏上绘制正弦曲线。具体要求如下:1在OLED屏上绘制一条正弦曲线2使用K1和K2键控制在OLED屏上绘制正弦或余弦曲线3绘制动态正弦曲线。正弦曲线从右往左移动每500ms移动一次。例子:# mainpy -- put your code here!from pyb import OLEDdelay# Create

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

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