我在Raspberry Pi上连接了一个20 * 4的LCD屏幕。它有效。
我有一个代码来筛选几个句子并循环它们
但是我找不到合适的方法来暂停每4个句子并在接下来的4个句子之前清除屏幕
这是实际代码(编辑时因为粘贴时我有缩进更改)
def typewriter_like(sentence, lcd_line, delay=0.7):
for i,letter in enumerate(sentence):
lcd_byte(lcd_line, LCD_CMD)
lcd_string(sentence[:i+1],1)
time.sleep(delay)
mots = (("EXAMPLE", "EXAMPLES", "EXAMPLESS", "EXAMPLESSS"),
("ONE", "TWO", "THREE", "FOUR"),
("LULU", "FIFI", "RIRI", "TATA"))
lcds = (0x80, 0xC0, 0x94, 0xD4)
list(zip(mots,lcds))
[(('EXAMPLE', 'EXAMPLES', 'EXAMPLESS', 'EXAMPLESSS'),128),(('ONE', 'TWO', 'THREE','FOUR'),192),(('LULU', 'FIFI', 'RIRI', 'TATA'),148)]
while True:
for mot in mots:
for word, lcd in zip(mot, lcds):
typewriter_like(word, lcd)
time.sleep(10)
for lcd in lcds:
lcd_byte(lcd, LCD_CMD)
lcd_string("",2)
time.sleep(4)
我想要的是暂停前4个单词...然后在打印4个下一个单词之前擦除所有内容(全部清除)
实施例 例子 EXAMPLESS EXAMPLESSS
保持打印10秒钟 然后全部清除
ONE 二 三 四个......
保持打印10秒
等...
最后一个循环...... 有人能帮助我吗?
答案 0 :(得分:0)
您只需修改缩进
即可 while True:
for mot in mots:
for word, lcd in zip(mot, lcds):
typewriter_like(word, lcd)
time.sleep(10)
for word, lcd in zip(mot, lcds):
typewriter_like(" " * len(word), lcd)