Output basic weather to LCD on Arduino using Johnny-five
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
/* | |
wiring diagram: https://github.com/rwaldron/johnny-five/raw/master/docs/breadboard/lcd.png | |
usage: | |
npm install feedparser johnny-five request | |
node lcd.js | |
*/ | |
var five = require("johnny-five"), | |
request = require("request"), | |
FeedParser = require("feedparser"), | |
board, lcd, req, feedparser, | |
item, items = [], message = []; | |
board = new five.Board(); | |
req = request("http://open.live.bbc.co.uk/weather/feeds/en/ox4/observations.rss"), | |
feedparser = new FeedParser(); | |
req.on('response', function (res) { | |
var stream = this; | |
if (res.statusCode != 200) return this.emit('error', new Error('Bad status code')); | |
stream.pipe(feedparser); | |
}); | |
feedparser.on('error', function (err) { | |
console.log(err); | |
}); | |
feedparser.on('readable', function () { | |
var stream = this, meta = this.meta; | |
while (item = stream.read()) { | |
var props = item['rss:title']['#'].split(', '); | |
message[0] = props[0].replace(/(\d{2}\:\d{2}).*$/,'$1'); | |
message[1] = 'Temp: ' + props[1].replace(/\(.*$/, ''); | |
} | |
}); | |
board.on("ready", function() { | |
lcd = new five.LCD({ | |
pins: [7, 8, 9, 10, 11, 12], | |
}); | |
lcd.on("ready", function() { | |
lcd.cursor(0, 0); | |
lcd.print(message[0]) | |
lcd.cursor(1, 0); | |
lcd.print(message[1]); | |
}); | |
this.repl.inject({ | |
lcd: lcd | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment