Micropython学习交流群 学习QQ群:786510434 提供多种固件下载和学习交流。

Micropython-扇贝物联 QQ群:31324057 扇贝物联是一个让你与智能设备沟通更方便的物联网云平台

Micropython学习交流群 学习QQ群:468985481 学习交流ESP8266、ESP32、ESP8285、wifi模块开发交流、物联网。

Micropython老哥俩的IT农场分享QQ群:929132891 为喜欢科创制作的小白们分享一些自制的计算机软硬件免费公益课程,由两位多年从事IT研发的中年大叔发起。

Micropython ESP频道

micropython esp32 ssd1306滚动方式,比较全面,横竖的都有,速度可调节


ssd1306滚动方式,比较全面,横竖的都有,速度可调节

from machine import I2C,Pin         #从machine模块导入I2C、Pin子模块
from ssd1306 import SSD1306_I2C     #从ssd1306模块中导入SSD1306_I2C子模块
import framebuf
from time import sleep

i2c = I2C(sda=Pin(22), scl=Pin(21))   #I2C初始化:sda--> 13, scl --> 14
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c) #OLED显示屏初始化:128*64分辨率,OLED的I2C地址是0x3c
oled_width = 128
oled_height = 64
screen1_row1 = "Screen 1, row 1"
screen1_row2 = "Screen 1, row 2"
screen1_row3 = "Screen 1, row 3"

screen2_row1 = "Screen 2, row 1"
screen2_row2 = "Screen 2, row 2"

screen3_row1 = "Screen 3, row 1"

screen1 = [[0, 0 , screen1_row1], [0, 16, screen1_row2], [0, 32, screen1_row3]]
screen2 = [[0, 0 , screen2_row1], [0, 16, screen2_row2]]
screen3 = [[0, 40 , screen3_row1]]

# Scroll in screen horizontally from left to right
def scroll_in_screen(screen):
 for i in range (0, oled_width+1, 4):
   for line in screen:
     oled.text(line[2], -oled_width+i, line[1])
   oled.show()
   if i!= oled_width:
     oled.fill(0)

# Scroll out screen horizontally from left to right
def scroll_out_screen(speed):
 for i in range ((oled_width+1)/speed):
   for j in range (oled_height):
     oled.pixel(i, j, 0)
   oled.scroll(speed,0)
   oled.show()

# Continuous horizontal scroll
def scroll_screen_in_out(screen):
 for i in range (0, (oled_width+1)*2, 1):
   for line in screen:
     oled.text(line[2], -oled_width+i, line[1])
   oled.show()
   if i!= oled_width:
     oled.fill(0)

# Scroll in screen vertically
def scroll_in_screen_v(screen):
 for i in range (0, (oled_height+1), 1):
   for line in screen:
     oled.text(line[2], line[0], -oled_height+i+line[1])
   oled.show()
   if i!= oled_height:
     oled.fill(0)

# Scroll out screen vertically
def scroll_out_screen_v(speed):
 for i in range ((oled_height+1)/speed):
   for j in range (oled_width):
     oled.pixel(j, i, 0)
   oled.scroll(0,speed)
   oled.show()

# Continous vertical scroll
def scroll_screen_in_out_v(screen):
 for i in range (0, (oled_height*2+1), 1):
   for line in screen:
     oled.text(line[2], line[0], -oled_height+i+line[1])
   oled.show()
   if i!= oled_height:
     oled.fill(0)

while True:

 # Scroll in, stop, scroll out (horizontal)
 scroll_in_screen(screen1)
 sleep(2)
 scroll_out_screen(4)

 scroll_in_screen(screen2)
 sleep(2)
 scroll_out_screen(4)

 scroll_in_screen(screen3)
 sleep(2)
 scroll_out_screen(4)

 # Continuous horizontal scroll
 scroll_screen_in_out(screen1)
 scroll_screen_in_out(screen2)
 scroll_screen_in_out(screen3)

 # Scroll in, stop, scroll out (vertical)
 scroll_in_screen_v(screen1)
 sleep(2)
 scroll_out_screen_v(4)

 scroll_in_screen_v(screen2)
 sleep(2)
 scroll_out_screen_v(4)

 scroll_in_screen_v(screen3)
 sleep(2)
 scroll_out_screen_v(4)

 # Continuous verticall scroll
 scroll_screen_in_out_v(screen1)
 scroll_screen_in_out_v(screen2)
 scroll_screen_in_out_v(screen3)


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 ESP56.com All Rights Reserved

执行时间: 0.0099489688873291 seconds