Last active
August 29, 2015 14:06
-
-
Save drnugent/98bc4dbf0f72d6e9edf2 to your computer and use it in GitHub Desktop.
PubNub/Tessel Audio Integration
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 pubnub = require("pubnub").init({publish_key: "demo", subscribe_key: "demo" }); | |
var tessel = require("tessel") | |
, ambient = require('ambient-attx4').use(tessel.port['A']); | |
var conn = function() { | |
console.log("Running connect function"); | |
ambient.on('ready', function () { | |
ambient.setSoundTrigger(0.1); | |
ambient.on('sound-trigger', function(data) { | |
console.log("Something happened with sound: ", data); | |
pubnub.publish({channel: "tessel-light", message: "Sound detected!"}); | |
// Clear it | |
ambient.clearSoundTrigger(); | |
//After 1.5 seconds reset sound trigger | |
setTimeout(function () { | |
ambient.setSoundTrigger(0.1); | |
},1500); | |
}); | |
}); | |
} | |
setTimeout(conn, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment