def rain():
    forecast = darksky.Forecast(api_key, latitude, longitude, units=units)
    hourly = forecast.hourly
    rain = hourly[1].precipProbability*100
    try:
        if rain <=19:
            print("The chance of rain is very low")
            blinkt.set_all(0, 215, 0)  # Green ( very low)
            blinkt.show()
        elif (rain >=20) and (rain <=39):
            print("The chance of rain is low")
            blinkt.set_all(255, 155, 0) # Yellow (low)
            blinkt.show()
        elif (rain >=40) and (rain <=59):
            print("The chance of rain is moderate!")
            blinkt.set_all(255, 35, 0)  # Orange (moderate)
            blinkt.show()
        elif (rain >=60) and (rain <=79):
            print("The chance of rain is very high!\nDon't forget your umbrella!")
            blinkt.set_all(205, 0, 0)   # Red (high)
            blinkt.show()
        else:
            print("The chance of rain is extreme!\nIt's probably raining now!")
            blinkt.set_all(0, 10, 255)  # Blue (extreme)
            blinkt.show()
    except:
        print("Connection Error")
def rainWarning():
    forecast = darksky.Forecast(api_key, latitude, longitude, units=units)
    hourly = forecast.hourly
    rain = hourly[1].precipProbability * 100
    if rain == 0:
        backlight.set_graph(0)
    elif (rain > 1) and (rain <= 9):
        backlight.set_graph(0.1)
    elif (rain >= 10) and (rain <= 19):
        backlight.set_graph(0.2)
    elif (rain >= 20) and (rain <= 29):
        backlight.set_graph(0.3)
    elif (rain >= 30) and (rain <= 39):
        backlight.set_graph(0.4)
    elif (rain >= 40) and (rain <= 49):
        backlight.set_graph(0.5)
    elif (rain >= 50) and (rain <= 59):
        backlight.set_graph(0.6)
    elif (rain >= 60) and (rain <= 69):
        backlight.set_graph(0.7)
    elif (rain >= 70) and (rain <= 79):
        backlight.set_graph(0.8)
    elif (rain >= 80) and (rain <= 89):
        backlight.set_graph(0.9)
    else:
        backlight.set_graph(1.0)
Пример #3
0
def display():
    forecast = darksky.Forecast(api_key, latitude, longitude, units=units)
    current = forecast.currently
    temp = current.temperature
    temp = str(temp)
    humidity = current.humidity*100
    humidity = str(humidity)
    rain = current.precipProbability*100
    rain = str(rain)
    try:
        screen.clear()
        print("Current weather:\nTemperture: "+temp+" C\nHumidity: "+humidity+"%\nRain: "+rain+"%")
        text.write("Current weather:\nTemp: "+temp+" C\nHumidity: "+humidity+"%\nRain: "+rain+"%")
    except:
        text.write("Connection Error!")
def display():
    forecast = darksky.Forecast(api_key, latitude, longitude, units=units)
    current = forecast.currently
    temp = current.temperature
    temp = str(temp)
    humidity = current.humidity * 100
    humidity = str(humidity)
    rain = current.precipProbability * 100
    rain = str(rain)
    uvIndex = current.uvIndex
    uv = str(uvIndex)
    if uvIndex <= 2.9:
        backlight.rgb(90, 148, 35)  # Green (low)
    elif (uvIndex >= 3) and (uvIndex <= 5.9):
        backlight.rgb(241, 227, 54)  # Yellow (moderate)
    elif (uvIndex >= 6) and (uvIndex <= 7.9):
        backlight.rgb(217, 90, 18)  # Orange (high)
    elif (uvIndex >= 8) and (uvIndex <= 10.9):
        backlight.rgb(185, 2, 34)  # Red (very high)
    else:
        backlight.rgb(99, 74, 195)  # Violet (extreme)
    try:
        lcd.clear()
        lcd.set_cursor_position(0, 0)
        print("Temperture: " + temp + " C")
        lcd.write("Temp: " + temp + "\xf2C")
        lcd.set_cursor_position(0, 1)
        print("Humidity: " + humidity + "%")
        lcd.write("Humidity: " + humidity + "%")
        lcd.set_cursor_position(0, 2)
        print("Rain: " + rain + "%")
        lcd.write("Rain: " + rain + "%")
        print("UV Index: " + uv + "")
    except:
        lcd.write("Connection Error")

    # Press the button on the joystick to exit
    @nav.on(nav.BUTTON)
    def handle_button(pin):
        lcd.clear()
        backlight.rgb(0, 0, 0)
        backlight.set_graph(0)
        os._exit(1)
Пример #5
0
def display():
    forecast = darksky.Forecast(api_key, latitude, longitude, units=units)
    current = forecast.currently
    daily = forecast.daily
    summary = current.summary
    summary = str(summary)
    temp = current.temperature
    temp = str(temp)
    humidity = current.humidity * 100
    humidity = str(humidity)
    rain = current.precipProbability * 100
    rain = str(rain)

    weekday = date.today()
    day_Name = date.strftime(weekday, '%A')
    day_month_year = date.strftime(weekday, '%Y %b %-d')

    try:
        screen.clear()
        print("Summary: " + summary + "\nTemperture: " + temp +
              " C\nHumidity: " + humidity + "%\nRain: " + rain + "%")
        text.AddText(
            (day_Name) + ', ' + (day_month_year) + '\n' + (summary),
            0,
            0,
            18,
            Id="Line1",
            fontPath='/home/pi/weather-pi-data/fonts/Roboto-Black.ttf')
        # text.AddText((day_Name) + ', ' + (day_month_year) + '\n' + (summary), 0, 0, 18, Id="Line1", fontPath='/home/pi/weather-pi-data/fonts/Roboto-Black.ttf')
        # text.AddText((summary), 0, 18, 14, Id="Line2", fontPath='/home/pi/weather-pi-data/fonts/Roboto-Bold.ttf')
        text.AddText('T: ' + (temp) + 'C ' + 'H: ' + (humidity) + '% R: ' +
                     (rain) + '%',
                     0,
                     36,
                     14,
                     Id="Line3",
                     fontPath='/home/pi/weather-pi-data/fonts/Roboto-Bold.ttf')
        # text.write(""+summary+"\nTemp: "+temp+" C\nHumidity: "+humidity+"%\nRain: "+rain+"%", 18, fontPath='/home/pi/weather-pi-data/fonts/Roboto-Black.ttf', maxLines = 10)
    except:
        text.UpdateText("Line1", "Connection Error!")