Question: hello, how can i displaye time a 16 x 2 LCD or how to display the value of value to the LCD ( i get
hello,
how can i displaye time a 16 x 2 LCD or how to display the value of "value" to the LCD ( i get an error) . Im using a raspberry pi and my code is in python
import time
import sys
import Adafruit_CharLCD as LCD
import Adafruit_GPIO.MCP230xx as MCP
from datetime import datetime
# Define MCP pins connected to the LCD.
lcd_rs = 0
lcd_en = 1
lcd_d4 = 2
lcd_d5 = 3
lcd_d6 = 4
lcd_d7 = 5
lcd_red = 6
lcd_green = 7
lcd_blue = 8
# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows = 2
# Initialize MCP23017 device using its default 0x20 I2C address.
gpio = MCP.MCP23017()
# Initialize the LCD using the pins
lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue,
gpio=gpio)
# Print a two line message
lcd.message('Hello!')
# Wait 5 seconds
time.sleep(5.0)
# time and ip address
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 '))
lcd.message('IP %s' % ( ipaddr ) )
sleep(2)
# Show some basic colors.
value = float(input("Enter Value : "))
if value < 45:
lcd.set_color(0.0, 0.0, 1.0)
lcd.clear()
lcd.message('Below optimal temperature')
print('COLD'.format(value))
time.sleep(3.0)
if value > 70:
lcd.set_color(1.0, 0.0, 0.0)
lcd.clear()
lcd.message('RED')
time.sleep(3.0)
else:
lcd.set_color(0.0, 1.0, 0.0)
lcd.clear()
lcd.message('GREEN')
time.sleep(3.0)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
