本站改版新增arduino频道

Micropython
Arduino

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
晋ICP备14006235号-22 晋公网安备14108102001165号

执行时间: 0.009660005569458 seconds