Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
- from subprocess import *
- from time import sleep, strftime
- from datetime import datetime
- lcd = Adafruit_CharLCDPlate()
- cmd = "ip addr show wlan0 | grep inet | awk '{print $2}' | cut -d/ -f1"
- lcd.begin(16,1)
- # Function to return the IP
- def run_cmd(cmd):
- p = Popen(cmd, shell=True, stdout=PIPE)
- output = p.communicate()[0]
- return output
- # Here is a nice function returning the colors you want
- def change_color(color):
- # Here I've done an array of the available colors
- color_array = ['RED', 'YELLOW', 'GREEN', 'TEAL', 'BLUE', 'VIOLET']
- # The returned colors is lcd.<chosenColor>
- return lcd.colors_array[color]
- # This step allows you to set the first color
- color = 0
- lcd.backlight(change_color(color))
- while 1:
- # Here I get the current time for the entire loop
- current_time = datetime.now()
- # If we've reach the time HH:MM:00, then the backlight is changed
- if (current_time.strftime('%S') == '00') :
- lcd.backlight(change_color(color))
- color = (color + 1) % 6
- lcd.clear()
- ipaddr = run_cmd(cmd)
- lcd.message(current_time.strftime('%b %d %l:%M %p\n'))
- lcd.message('IP %s' % ( ipaddr ) )
- # Otherwise, we just display the time
- #lcd.clear()
- #ipaddr = run_cmd(cmd)
- #lcd.message(current_time.strftime('%b %d %l:%M %p\n'))
- #lcd.message('IP %s' % ( ipaddr ) )
- sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement