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=60b=30c=8d=4 oled.rect(a,b,c,d,1) #画矩形oled.show() #执行显示while a>2 :oled.fill(0) #清空屏幕a-=2b-=1c+=4d+=2oled.rect(a,b,c,d,1) #画矩形oled.show() #执行显示while a<60 :oled.fill(1) #清空屏幕a+=2b+=1c-=4d-=2oled.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+=3oled.rect(a,b,c,d,1) #画矩形oled.show() #执行显示while b<40 :oled.fill(1) #清空屏幕b+=2oled.fill_rect(a,b,c,d,0) #画矩形oled.show() #执行显示while a>5 :oled.fill(0) #清空屏幕a-=3oled.rect(a,b,c,d,1) #画矩形oled.show() #执行显示while b>5 :oled.fill(1) #清空屏幕b-=2oled.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=60b=30c=8d=4e=60f=30g=8h=4oled.rect(a,b,c,d,1) #画矩形oled.show() #执行显示while a>50 :e-=2f-1g+=4h+=2oled.fill(0) #清空屏幕while a>2 : a-=8b-=4c+=16d+=8oled.rect(a,b,c,d,1) #画矩形oled.show() #执行显示a=eb=fc=gd=h