Last active
August 29, 2015 13:55
-
-
Save jonasryberg/8775271 to your computer and use it in GitHub Desktop.
Feelometer - hämtar information om hur kallt vädret känns från wunderground och visar den på en Raspberry pi med en PiGlow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=latin1 | |
# Feelometer - hämtar information om hur kallt vädret känns från wunderground och visar | |
# den på en Raspberry pi med en PiGlow från Pimoroni | |
# | |
# av Jonas Ryberg | |
# Kräver biblioteket PyGlow som hämtas på https://github.com/benleb/PyGlow | |
# | |
# ------------------------------ | |
# Så här ska dioderna på PiGlow tolkas | |
# | |
# blå led = -1 | |
# vit led = -10 | |
# | |
# grön led = 1 | |
# röd led = 10 | |
# gul led = 5 | |
# ------------------------------ | |
from urllib2 import urlopen | |
import json | |
from pyglow import PyGlow # importerar funktioner for att styra PiGlow | |
from time import sleep | |
pyglow = PyGlow() | |
# Hämta data för Stockholm från wunderground.com | |
req = urlopen('http://api.wunderground.com/api/din-api-nyckel/conditions/q/SE/stockholm.json') | |
parsed_json = json.load(req) | |
feelslike = int(parsed_json['current_observation']['feelslike_c']) | |
# Definierar variabler | |
styrka = 100 | |
blue = 0 | |
green = 0 | |
yellow = 0 | |
red = 0 | |
white = 0 | |
# feelslike = -3 # för test | |
# avgör vilka dioder som ska tändas | |
if feelslike == 0: #om nollgradigt | |
blue = 1 | |
green = 1 | |
if feelslike > 0: #om plussgrader | |
red = int(feelslike/10) | |
yellow = int((feelslike-red*10)/5) | |
green = feelslike-red*10-yellow*5 | |
if green > 3: | |
yellow = 0 | |
red = red + 1 | |
blue = 1 | |
green = 0 | |
if feelslike < 0: #om minusgrader | |
feelslike = -feelslike | |
white = int(feelslike/10) | |
blue = feelslike - white*10 | |
if blue > 3: | |
white = white+1 | |
if blue == 4: | |
green = 1 | |
yellow = 1 | |
blue = 0 | |
if blue == 5: | |
yellow = 1 | |
blue = 0 | |
if blue == 6: | |
yellow = 1 | |
blue = 1 | |
if blue > 6: | |
green = 10 - blue | |
blue = 0 | |
# för test | |
# ----------------------------- | |
# print'blue = ' + str(blue) | |
# print'green = ' + str(green) | |
# print'yellow = ' + str(yellow) | |
# print'red = ' + str(red) | |
# print'white = ' + str(white) | |
# ------------------------------ | |
''' | |
led-adresser | |
pyglow.led(18,100)#vit | |
pyglow.led(12,100)#vit | |
pyglow.led(6,100) #vit | |
pyglow.led(5,100) #blå | |
pyglow.led(11,100)#blå | |
pyglow.led(17,100)#blå | |
pyglow.led(16,100)#grön | |
pyglow.led(10,100)#grön | |
pyglow.led(4,100) #grön | |
pyglow.led(3,100) #gul | |
pyglow.led(9,100) #gul | |
pyglow.led(15,100) #gul | |
pyglow.led(2,100) #orange | |
pyglow.led(8,100) #orange | |
pyglow.led(14,100) #orange | |
pyglow.led(1,100) #röd | |
pyglow.led(7,100) #röd | |
pyglow.led(13,100) #röd | |
''' | |
pyglow.all(0) | |
# tänd led | |
while white > 0: | |
pyglow.led((white*6),styrka) | |
white = white - 1 | |
start = 1 | |
while red > 0: | |
pyglow.led(start,styrka) | |
red = red -1 | |
start = start + 6 | |
start = 3 | |
while yellow > 0: | |
pyglow.led(start,styrka) | |
yellow = yellow -1 | |
start = start + 6 | |
start = 4 | |
while green > 0: | |
pyglow.led(start,styrka) | |
green = green -1 | |
start = start + 6 | |
start = 5 | |
while blue > 0: | |
pyglow.led(start,styrka) | |
blue = blue - 1 | |
start = start + 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment