我有一段代码(在下面)可以在我的OLED上滚动一个长字符串…它可以工作,但它很难看而且不是动态的。
我想我可以得到var_read_file
中的字符数,然后执行for
循环或while
循环,使字符串根据字符串的长度滚动
我的想法是这样的:
my_str_count = (len(var_read_file))
loopcounter = 0
scrollindex = 1
while my_str_count > loopcounter:
scrollindex = scrollindex + 5
display.fill(0)
display.text(var_read_file, scrollindex, 15, 1)
display.show()
time.sleep(0.1)
loopcounter = loopcounter + 1
以下是当前的丑陋代码:
def myoutboundscroll():
display.fill(0)
display.text(var_read_file, 0, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -5, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -10, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -15, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -20, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -25, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -30, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -35, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -40, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -45, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -50, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -55, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -60, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -65, 15, 1)
display.show()
display.fill(0)
display.text(var_read_file, -70, 15, 1)
display.show()
根据你的回答:
通过一些小的调整,我的想法奏效了:
相关问题 更多 >
编程相关推荐