Created
November 22, 2016 19:34
-
-
Save MaffooBristol/45a1319ff81316384e3d503dbe84a04b to your computer and use it in GitHub Desktop.
Festivitron 3000
This file contains hidden or 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
const five = require('johnny-five'); | |
const board = new five.Board(); | |
const opts = { | |
outputPin: 9, | |
throttleTimeout: 60, | |
}; | |
let timeout = null; | |
// Ensure that the Arduino has fully loaded before doing owt. | |
board.on('ready', function () { | |
// Initiate the twittering. | |
const twitter = require('./twitter'); | |
twitter.on('tweet', () => { | |
// Write the pin out to 1 when a tweet is received. | |
this.digitalWrite(opts.outputPin, this.MODES.OUTPUT); | |
// Create a new timeout for the latest tweet received. | |
clearTimeout(timeout); | |
// When the throttle time has elapsed, write the pin to 0. | |
timeout = setTimeout(() => this.digitalWrite(opts.outputPin, this.MODES.INPUT), opts.throttleTimeout); | |
}); | |
}); |
This file contains hidden or 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
const Twit = require('twit'); | |
const twitter = new Twit({ | |
consumer_key: 'do one', | |
consumer_secret: 'nah mate', | |
access_token: 'secrets brav', | |
access_token_secret: 'go away mum', | |
}); | |
const stream = twitter.stream('statuses/filter', {track: 'christmas'}); | |
stream.on('tweet', (tweet) => console.log('Received tweet! Text: ' + tweet.text)); | |
module.exports = stream; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment