Last active
August 29, 2015 14:06
-
-
Save drnugent/b9eeffe1bcc6901a53c0 to your computer and use it in GitHub Desktop.
Tessel-PubNub Demo 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']) | |
, 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