ESP32(MicroPython) 几个动画

ESP32(MicroPython)几个动画

本次发布的动画程序如下

矩形缩放

'''
接线:OLED(IIC)
       SCL-->(18)
       SDA-->(23)         
'''

#导入Pin模块
from machine import Pin
import time
from machine import SoftI2C
from ssd1306 import SSD1306_I2C  #I2C的oled选该方法
import random

#创建硬件I2C对象
#i2c=I2C(0,sda=Pin(19), scl=Pin(18), freq=400000)

#创建软件I2C对象
i2c = SoftI2C(sda=Pin(23), scl=Pin(18))
#创建OLED对象,OLED分辨率、I2C接口
oled = SSD1306_I2C(128, 64, i2c)

#程序入口
if __name__=="__main__":
 while True:
    a=60
    b=30
    c=8
    d=4 
    oled.rect(a,b,c,d,1)  #画矩形
    oled.show()  #执行显示
    while a>2 :
        oled.fill(0)  #清空屏幕
        a-=2
        b-=1
        c+=4
        d+=2
        oled.rect(a,b,c,d,1)  #画矩形
        oled.show()  #执行显示
    while a<60 :
        oled.fill(1)  #清空屏幕
        a+=2
        b+=1
        c-=4
        d-=2
        oled.fill_rect(a,b,c,d,0)  #画矩形
        oled.show()  #执行显示
    

矩形下落(改版)

'''
接线:OLED(IIC)
       SCL-->(18)
       SDA-->(23)         
'''

#导入Pin模块
from machine import Pin
import time
from machine import SoftI2C
from ssd1306 import SSD1306_I2C  #I2C的oled选该方法
import random

#创建硬件I2C对象
#i2c=I2C(0,sda=Pin(19), scl=Pin(18), freq=400000)

#创建软件I2C对象
i2c = SoftI2C(sda=Pin(23), scl=Pin(18))
#创建OLED对象,OLED分辨率、I2C接口
oled = SSD1306_I2C(128, 64, i2c)

#程序入口
if __name__=="__main__":
   while True:
            a=random.randint(2,110)
            b=random.randint(5,25)
            c=random.randint(5,20)
            d=random.randint(2,10)
            oled.rect(a,1,b,c,1)  #画矩形
            oled.show()  #执行显示
            oled.hline(0,0,128,0)  #清除移动前显示区
            oled.scroll(0,1)  #指定像素X轴移动
            time.sleep_ms(2)

矩形移动

'''
接线:OLED(IIC)
       SCL-->(18)
       SDA-->(23)         
'''

#导入Pin模块
from machine import Pin
import time
from machine import SoftI2C
from ssd1306 import SSD1306_I2C  #I2C的oled选该方法
import random

#创建硬件I2C对象
#i2c=I2C(0,sda=Pin(19), scl=Pin(18), freq=400000)

#创建软件I2C对象
i2c = SoftI2C(sda=Pin(23), scl=Pin(18))
#创建OLED对象,OLED分辨率、I2C接口
oled = SSD1306_I2C(128, 64, i2c)

#程序入口
if __name__=="__main__":
 while True:
    a=random.randint(5,15)
    b=random.randint(5,15)
    c=random.randint(8,23)
    d=random.randint(8,23) 
    oled.rect(a,b,c,d,1)  #画矩形
    oled.show()  #执行显示
    while a<100 :
        oled.fill(0)  #清空屏幕
        a+=3
        oled.rect(a,b,c,d,1)  #画矩形
        oled.show()  #执行显示
    while b<40 :
        oled.fill(1)  #清空屏幕
        b+=2
        oled.fill_rect(a,b,c,d,0)  #画矩形
        oled.show()  #执行显示
    while a>5 :
        oled.fill(0)  #清空屏幕
        a-=3
        oled.rect(a,b,c,d,1)  #画矩形
        oled.show()  #执行显示
    while b>5 :
        oled.fill(1)  #清空屏幕
        b-=2
        oled.fill_rect(a,b,c,d,0)  #画矩形
        oled.show()  #执行显示   

同心矩形放大

'''
接线:OLED(IIC)
       SCL-->(18)
       SDA-->(23)         
'''

#导入Pin模块
from machine import Pin
import time
from machine import SoftI2C
from ssd1306 import SSD1306_I2C  #I2C的oled选该方法
import random

#创建硬件I2C对象
#i2c=I2C(0,sda=Pin(19), scl=Pin(18), freq=400000)

#创建软件I2C对象
i2c = SoftI2C(sda=Pin(23), scl=Pin(18))
#创建OLED对象,OLED分辨率、I2C接口
oled = SSD1306_I2C(128, 64, i2c)

#程序入口
if __name__=="__main__":
 while True:
    a=60
    b=30
    c=8
    d=4
    e=60
    f=30
    g=8
    h=4
    oled.rect(a,b,c,d,1)  #画矩形
    oled.show()  #执行显示
    while a>50 :
        e-=2
        f-1
        g+=4
        h+=2
        oled.fill(0)  #清空屏幕
        while a>2 :    
            a-=8
            b-=4
            c+=16
            d+=8
            oled.rect(a,b,c,d,1)  #画矩形
            oled.show()  #执行显示
        a=e
        b=f
        c=g
        d=h

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路易斯720

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值