Skip to content

Instantly share code, notes, and snippets.

@drnugent
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drnugent/b9eeffe1bcc6901a53c0 to your computer and use it in GitHub Desktop.
Save drnugent/b9eeffe1bcc6901a53c0 to your computer and use it in GitHub Desktop.
Tessel-PubNub Demo Integration
var pubnub = require("pubnub").init({publish_key: "demo", subscribe_key: "demo" });
var tessel = require("tessel")
, ambient = require('ambient-attx4').use(tessel.port['A'])
, rfid = require('rfid-pn532').use(tessel.port['D'])
;
var conn = function() {
console.log("Running connect function");
rfid.on('ready', function (version) {
console.log('Ready to read RFID card');
rfid.on('data', function(card) {
console.log('UID:', card.uid.toString('hex'));
pubnub.publish({
channel : "tessel",
message : { "card": card }
});
});
});
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", message: "Sound!"});
// 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