2014-03-24 80 views
0

我有一段代碼(來自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) 

回答

0

從該示例中的相關代碼:

#!/usr/bin/python 

from Adafruit_CharLCD import Adafruit_CharLCD 
lcd = Adafruit_CharLCD() 
lcd.begin(16,1) 
lcd.message(someKindofString) 

...其中someKindofString是你的消息。所以它看起來不像寫任何東西很難。 如果更多的是「我怎麼知道命令行參數是什麼?」方面,那麼你想看看sys.argvtutorial