Created
February 18, 2014 03:19
-
-
Save monteslu/9064104 to your computer and use it in GitHub Desktop.
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
var SkynetSerialPort = require('skynet-serial').SerialPort; | |
var skynet = require('skynet'); | |
var firmata = require('firmata'); | |
var myId = '26ce1ac8-2133-4faa-bcb9-3548fec5f11a'; | |
var token = '2bb7507b5a74494a8be233b068d8c1e'; | |
//jake's id | |
var sendId = '744d4bd1-97be-11e3-a924-db90dd71caef'; | |
var token, serialPort, board, firm; | |
var pinState = 1; | |
var conn = skynet.createConnection({ | |
uuid: myId, | |
token: token | |
}); | |
conn.on('notReady', function(data){ | |
console.log('UUID FAILED AUTHENTICATION!', data); | |
// Register device | |
conn.register({ | |
uuid: myId, | |
token: token, | |
type: 'serial' | |
}, function (data) { | |
console.log('registered', data); | |
conn.emit('ready', data); | |
}); | |
}); | |
conn.on('ready', function(data){ | |
console.log('UUID AUTHENTICATED!', data); | |
serialPort = new SkynetSerialPort(conn, sendId); | |
firm = new firmata.Board(serialPort, function (err, ok) { | |
if (err){ | |
console.log('could node connect to board' , err); | |
throw err; | |
} | |
console.log("board loaded", ok); | |
togglePin(); | |
}); | |
}); | |
function togglePin(){ | |
console.log('toggling', pinState); | |
if(pinState){ | |
pinState = 0; | |
}else{ | |
pinState = 1; | |
} | |
firm.digitalWrite(13, pinState); | |
setTimeout(togglePin, 750); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment