Last active
August 29, 2015 14:09
-
-
Save saranrapjs/c7f717d9b8ba452a385c to your computer and use it in GitHub Desktop.
blink1 forecast.io warmer/cooler
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
var Forecast = require('forecast.io'), | |
options = { | |
APIKey: process.env.FORECAST_API_KEY | |
}, | |
forecast = new Forecast(options), | |
weathercolor = require('./weathercolor.js'); | |
forecast.get(40.681975, -74.003441, function (err, res, data) { | |
if (err) throw err; | |
var nowTemp = data.currently.temperature, | |
todaysHigh = data.daily.data[0].temperatureMax, | |
todaysLow = data.daily.data[0].temperatureMin; | |
console.log(new Date()) | |
console.log("NOW",nowTemp) | |
console.log("LOW",todaysLow) | |
console.log("HIGH", todaysHigh); | |
weathercolor(nowTemp) | |
}); |
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
{ | |
"name": "weatherlight", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"forecast.io": "0.0.9", | |
"node-blink1": "*", | |
"onecolor": "^2.4.2" | |
} | |
} |
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
var Blink1 = require('node-blink1'), | |
blink1, | |
util = require('util'), | |
color = require('onecolor') | |
try { | |
blink1 = new Blink1(); | |
} catch(e) { | |
} | |
var ranges = [{ | |
temp : 90, | |
rgb : [207, 57, 39], | |
}, { | |
temp : 80, | |
rgb : [238, 126, 38], | |
}, { | |
temp : 70, | |
rgb : [253, 249, 41], | |
}, { | |
temp : 60, | |
rgb : [110, 210, 40], | |
}, { | |
temp : 50, | |
rgb : [90, 219, 140], | |
}, { | |
temp : 40, | |
rgb : [68, 184, 219], | |
}, { | |
temp : 30, | |
rgb : [75, 56, 156], | |
}, { | |
temp : 20, | |
rgb : [148, 69, 188], // hsl(280, 47%, 50%}, ) | |
}, { | |
temp : 10, | |
rgb : [213, 117, 219] // hsl(296, 59%, 66%) | |
}]; | |
module.exports = function(temp) { | |
var upper = ranges.reduce(function(prev, current) { | |
return (current.temp < prev.temp && current.temp > temp) | |
? current | |
: prev; | |
}), | |
lower = ranges.reduceRight(function(prev, current) { | |
return (current.temp > prev.temp && current.temp < temp) | |
? current | |
: prev; | |
}), | |
rgb, pct; | |
if (upper.temp === lower.temp) { // weather extremes | |
rgb = upper.rgb; | |
} else { | |
pct = (temp - lower.temp)/(upper.temp-lower.temp); | |
rgb = []; | |
for (var i = 0; i < 3; i++) { | |
rgb[i] = ((upper.rgb[i] - lower.rgb[i]) * pct) + lower.rgb[i]; | |
}; | |
} | |
if (blink1) blink1.fadeToRGB(100, rgb[0], rgb[1], rgb[2]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment