Advertisement
Guest User

Untitled

a guest
Mar 26th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  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. def run_cmd(cmd):
  15.     p = Popen(cmd, shell=True, stdout=PIPE)
  16.     output = p.communicate()[0]
  17.     return output
  18.  
  19. # Here is a nice function returning the colors you want
  20. def change_color(color):
  21.  
  22.     if (color == 0):
  23.         return 'lcd.RED'
  24.        
  25.     elif (color == 1):
  26.         return 'lcd.YELLOW'
  27.        
  28.     elif (color == 2):
  29.         return 'lcd.GREEN'
  30.  
  31.     elif (color == 3):
  32.         return 'lcd.TEAL'
  33.        
  34.     elif (color == 4):
  35.         return 'lcd.BLUE'
  36.        
  37.     elif (color == 5):
  38.         return 'lcd.VIOLET'      
  39.  
  40. color = 0
  41.  
  42. while 1:
  43.  
  44.     # Here I get the current time for the entire loop
  45.     current_time = datetime.now()
  46.    
  47.     # If we've reach the time HH:MM:00, then the backlight is changed
  48.     if (current_time.strftime('%S') == '00') :
  49.         lcd.backlight(change_color(color))
  50.         color = (color + 1) % 6
  51.    
  52.     # Otherwise, we just display the time
  53.     lcd.clear()
  54.     ipaddr = run_cmd(cmd)
  55.     lcd.message(current_time.strftime('%b %d %l:%M:%S %p\n'))
  56.     lcd.message('IP %s' % ( ipaddr ) )
  57.     sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement