-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oscar Persson
committed
May 2, 2015
0 parents
commit 3c4e713
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
twitter_keys.json | ||
node_modules/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
var five = require('johnny-five'), | ||
Twitter = require('node-twitter'), | ||
MorseCode = require('morsecode'), | ||
morseConverter = new MorseCode(), | ||
keys = require('./twitter_keys.json'), | ||
board = new five.Board(), | ||
isBroadcasting = false; | ||
|
||
var BPM = 400; | ||
|
||
board.on('ready', function() { | ||
// Creates a piezo object and defines the pin to be used for the signal | ||
var piezo = new five.Piezo(3); | ||
|
||
// Injects the piezo into the repl | ||
board.repl.inject({ | ||
piezo: piezo | ||
}); | ||
|
||
registerTweet = function (morseStr, textStr) { | ||
if (isBroadcasting) return; | ||
console.log('SENDING:', textStr); | ||
|
||
var message = [], | ||
duration = 0; | ||
|
||
for (char in morseStr) { | ||
if (morseStr[char] === '.') { | ||
message.push(['C4', 1/8]); | ||
duration += 1/8; | ||
} else if (morseStr[char] === '_') { | ||
message.push(['C4', 1]); | ||
duration += 1; | ||
} | ||
|
||
if (morseStr[char] !== ' ') { | ||
message.push(null, 1/8); | ||
duration += 1/8; | ||
} | ||
} | ||
|
||
broadcastTweet(message, duration); | ||
} | ||
|
||
broadcastTweet = function (message, duration) { | ||
isBroadcasting = true; | ||
|
||
piezo.play({ | ||
song: message, | ||
tempo: BPM | ||
}); | ||
|
||
setTimeout( function() { | ||
// Ready for next tweet | ||
isBroadcasting = false; | ||
}, (4*duration*1000)/(BPM/60) + 2000); | ||
} | ||
|
||
|
||
|
||
var twitterStreamClient = new Twitter.StreamClient( | ||
keys.CONSUMER_KEY, | ||
keys.CONSUMER_SECRET, | ||
keys.TOKEN_KEY, | ||
keys.TOKEN_SECRET | ||
); | ||
|
||
twitterStreamClient.on('error', function(error) { | ||
console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message)); | ||
}); | ||
|
||
twitterStreamClient.on('tweet', function(tweet) { | ||
var textStr = tweet.text; | ||
var morseStr = morseConverter.translate(tweet.text); | ||
registerTweet(morseStr, textStr); | ||
}); | ||
|
||
twitterStreamClient.start(['teknodrom']); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "johnny-five", | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Oscar Persson", | ||
"dependencies": { | ||
"johnny-five": "latest", | ||
"node-twitter": "~0.5.2", | ||
"morsecode": "~1.0.0" | ||
} | ||
} |