from gpiozero import LED import smbus import time import os import colorama from colorama import Fore, Back, Style deg_f = chr(176)+ 'F' red = LED(19) green = LED(16) blue = LED(26) try: while True: # Get I2C bus bus = smbus.SMBus(1) bus.write_byte(0x40, 0xF5) time.sleep(0.3) # SI7021 address, 0x40 Read 2 bytes, Humidity data0 = bus.read_byte(0x40) data1 = bus.read_byte(0x40) # Convert the data humidity = ((data0 * 256 + data1) * 125 / 65536.0) - 6 time.sleep(0.3) bus.write_byte(0x40, 0xF3) time.sleep(0.3) # SI7021 address, 0x40 Read data 2 bytes, Temperature data0 = bus.read_byte(0x40) data1 = bus.read_byte(0x40) # Convert the data and output it celsTemp = ((data0 * 256 + data1) * 175.72 / 65536.0) - 46.85 fahrTemp = celsTemp * 1.8 + 32 if fahrTemp >= 85: print(Fore.RED + Style.BRIGHT + "Temperature is ----> %.2f" %fahrTemp,deg_f) print("Relative Humidity is ----> %.2f %%" %humidity) red.blink() green.on() blue.off() elif fahrTemp > 77 and fahrTemp < 85: print(Fore.RED + Style.BRIGHT + "Temperature is ----> %.2f" %fahrTemp,deg_f) print("Relative Humidity is ----> %.2f %%" %humidity) red.on() green.off() blue.off() elif fahrTemp >= 60 and fahrTemp <= 77: print(Fore.GREEN + Style.BRIGHT + "Temperature is ----> %.2f" %fahrTemp,deg_f) print("Relative Humidity is ----> %.2f %%" %humidity) red.off() green.on() blue.off() elif fahrTemp > 32 and fahrTemp < 60: print(Fore.BLUE + Style.BRIGHT + "Temperature is ----> %.2f" %fahrTemp,deg_f) print("Relative Humidity is ----> %.2f %%" %humidity) red.off() green.off() blue.on() elif fahrTemp <= 32: print(Fore.BLUE + Style.BRIGHT + "Temperature is ----> %.2f" %fahrTemp,deg_f) print("Relative Humidity is ----> %.2f %%" %humidity) red.off() green.off() blue.blink() else: red.off() green.off() blue.off() time.sleep(10) os.system('clear') except KeyboardInterrupt: GPIO.cleanup()