Guest User

Untitled

a guest
Mar 26th, 2014
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
  4. from subprocess import *
  5. from time import sleep, strftime
  6. from datetime import datetime
  7.  
  8. lcd = Adafruit_CharLCDPlate()
  9.  
  10. cmd = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
  11.  
  12. lcd.begin(16,1)
  13.  
  14. # Function to return the IP
  15. def run_cmd(cmd):
  16.     p = Popen(cmd, shell=True, stdout=PIPE)
  17.     output = p.communicate()[0]
  18.     return output
  19.  
  20. # Here is a nice function returning the colors you want
  21. def change_color(color):
  22.  
  23.     # Here I've done an array of the available colors
  24.     color_array = ['RED', 'YELLOW', 'GREEN', 'TEAL', 'BLUE', 'VIOLET']
  25.  
  26.     # The returned colors is lcd.<chosenColor>
  27.     return lcd.colors_array[color]
  28.  
  29.  
  30. # This step allows you to set the first color
  31. color = 0
  32. lcd.backlight(change_color(color))
  33.  
  34.  
  35. while 1:
  36.  
  37.     # Here I get the current time for the entire loop
  38.     current_time = datetime.now()
  39.    
  40.     # If we've reach the time HH:MM:00, then the backlight is changed
  41.     if (current_time.strftime('%S') == '00') :
  42.         lcd.backlight(change_color(color))
  43.         color = (color + 1) % 6
  44.         lcd.clear()
  45.         ipaddr = run_cmd(cmd)
  46.         lcd.message(current_time.strftime('%b %d %l:%M %p\n'))
  47.         lcd.message('IP %s' % ( ipaddr ) )
  48.        
  49.    
  50.     # Otherwise, we just display the time
  51.     #lcd.clear()
  52.     #ipaddr = run_cmd(cmd)
  53.     #lcd.message(current_time.strftime('%b %d %l:%M %p\n'))
  54.     #lcd.message('IP %s' % ( ipaddr ) )
  55.     sleep(1)
RAW Paste Data