[英]Send message to LCD via Command Line argument using Raspberry Pi
I have a piece of code (From the Adafruit website) to write chars to the LCD. 我有一段代码(来自Adafruit网站)可将字符写入LCD。 Is there a possibility of doing it via command line arguments?
是否可以通过命令行参数来实现?
Thank you in advance. 先感谢您。
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)
The relevant code from that example is: 该示例中的相关代码为:
#!/usr/bin/python
from Adafruit_CharLCD import Adafruit_CharLCD
lcd = Adafruit_CharLCD()
lcd.begin(16,1)
lcd.message(someKindofString)
...where someKindofString is your message. ...其中someKindofString是您的消息。 So it doesn't look like writing something arbitrary is hard.
因此,写任意东西看起来并不困难。 If it's more the "how do I know what the command line arguments are?"
如果更多,那么“我怎么知道命令行参数是什么?” aspect, then you want to look at sys.argv ( tutorial )
方面,那么您想看看sys.argv ( 教程 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.