我把一个液晶显示器连接到我正在做的一个项目上。我有许多输入/输出,我想根据输入的状态显示不同的消息。在我开始复杂化/添加更多硬件之前。我需要帮助。当没有输入激活时,我希望LCD显示消息“等待输入”,然后一旦收到输入,我希望显示“输入激活”。我目前使用的是while-true循环,但是当我清除LCD显示时问题就出现了,因为每次循环都会给屏幕上的文本带来脉冲。在while true循环之外,有没有更好的方法来实现这一点?你知道吗
这是我现在的密码
import I2C_LCD_driver
import time
import pigpio
mylcd = I2C_LCD_driver.lcd()
Debounce = 0.5
Input23 = 23
Input24 = 24
Input17 = 17
Output18 = 18
Output4 = 4
pi_GPIO = pigpio.pi()
pi_GPIO.set_mode(Input23, pigpio.INPUT)
pi_GPIO.set_pull_up_down(Input23 , pigpio.PUD_UP)
pi_GPIO.set_mode(Input24, pigpio.INPUT)
pi_GPIO.set_pull_up_down(Input24 , pigpio.PUD_UP)
pi_GPIO.set_mode(Input17, pigpio.INPUT)
pi_GPIO.set_pull_up_down(Input17 , pigpio.PUD_UP)
pi_GPIO.set_mode(Output18, pigpio.OUTPUT)
pi_GPIO.set_mode(Output4, pigpio.OUTPUT)
while True:
if pi_GPIO.read(Input23):
pi_GPIO.write(18, 0)
mylcd.lcd_clear()
mylcd.lcd_display_string("Input 1 Active", 1)
time.sleep(Debounce)
else:
pi_GPIO.read(Input23)
pi_GPIO.write(18, 1)
mylcd.lcd_clear()
mylcd.lcd_display_string("Awaiting Input", 1)
mylcd.lcd_display_string("Detection", 2)
time.sleep(Debounce)
当我用Arduino做类似的事情时,我用了一面旗子。在这种情况下,我确实需要一个
While True:
等价物,因为这是电路板的主要进程,在通电时必须在无限循环中运行。你知道吗您现在遇到的问题(我猜)是,每次循环命中以下代码时,您都在创建脉冲:
任何简单(尽管不合法)的修复方法都类似于(这是python3,对于dictionary迭代works a bit differently而不是2.7)这样。我还没有机会测试这个(所以我可能错过了一些东西/打了一些错字),但希望你能明白:
相关问题 更多 >
编程相关推荐