Created
December 8, 2014 05:36
-
-
Save tomsteele/e3bfaa3709ff8622f394 to your computer and use it in GitHub Desktop.
santa.js
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 Cylon = require('cylon'); | |
var EventEmitter = require('events').EventEmitter; | |
var Hapi = require('hapi'); | |
var bot = new EventEmitter(); | |
var on = false; | |
Cylon.robot({ | |
connections: { | |
arduino: { | |
adaptor: 'firmata', | |
port: '/dev/ttyACM0' | |
} | |
}, | |
devices: { | |
pin: { | |
driver: 'direct-pin', | |
pin: 6 | |
} | |
}, | |
work: function (my) { | |
bot.on('play', function () { | |
if (on) { | |
return; | |
} | |
my.pin.digitalWrite(1); | |
on = true; | |
setTimeout(function () { | |
my.pin.digitalWrite(0); | |
on = false; | |
}, 10000); | |
}); | |
} | |
}).start(); | |
var server = new Hapi.Server('0.0.0.0', 8000); | |
server.route({ | |
method: 'GET', | |
path: '/santa', | |
handler: function (request, reply) { | |
bot.emit('play'); | |
return reply('Happy Holidays!'); | |
} | |
}); | |
server.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment