使用Raspberry Pi通过命令行参数发送消息到LCD
问题描述:
我有一段代码(来自Adafruit网站)可以将字符写入LCD。有没有可能通过命令行参数来做到这一点?使用Raspberry Pi通过命令行参数发送消息到LCD
预先感谢您。
CODE:
#!/usr/bin/python
from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime
lcd = Adafruit_CharLCD()
cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"
lcd.begin(16,1)
def run_cmd(cmd):
p = Popen(cmd, shell=True, stdout=PIPE)
output = p.communicate()[0]
return output
while 1:
lcd.clear()
ipaddr = run_cmd(cmd)
lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n'))
lcd.message('IP %s' % (ipaddr))
sleep(2)