Last active
August 29, 2015 14:04
-
-
Save ikr7/bd27d7389d53e199a74e to your computer and use it in GitHub Desktop.
BBBであそぼう
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
// アレの commands/ に入れる | |
var Command = require('../lib/command.js'), | |
request = require('request'); | |
var fabeep = new Command(function(twit, data, CONFIG){ | |
request.get({ | |
'uri': 'http://192.168.7.2:8123/beep' // ←ここ適当に変えろ | |
}, function(){}); // ←エラーはにぎりつぶす | |
}); | |
fabeep.setTrigger(function(data, CONFIG){ | |
return data.event == 'favorite' && data.target.screen_name == CONFIG.MY_SCREEN_NAME; | |
}); | |
fabeep.setPermission({ | |
'me': true, | |
'following': true, | |
'others': true | |
}); | |
module.exports = fabeep; |
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
// なんもインストールしなくていいからBBB上でコレをそのまま動かす | |
var express = require('bonescript/node_modules/express'), | |
b = require('bonescript'); | |
b.pinMode('USR0', b.OUTPUT); | |
b.pinMode('USR1', b.OUTPUT); | |
b.pinMode('USR2', b.OUTPUT); | |
b.pinMode('USR3', b.OUTPUT); | |
b.pinMode('P9_42', b.OUTPUT); | |
var app = express(); | |
app.get('/', function(req, res){ | |
res.end('index page.'); | |
}); | |
app.get('/high', function(req, res){ | |
var n = req.query.n; | |
console.log(n); | |
if(0 <= n && n <= 3){ | |
b.digitalWrite('USR' + n, b.HIGH, function(){ | |
console.log(arguments); | |
res.end('OK'); | |
}); | |
}else{ | |
res.end('Not good number'); | |
} | |
}); | |
app.get('/low', function(req, res){ | |
var n = req.query.n; | |
console.log(n); | |
if(0 <= n && n <= 3){ | |
b.digitalWrite('USR' + n, b.LOW, function(){ | |
console.log(arguments); | |
res.end('OK'); | |
}); | |
}else{ | |
res.end('Not good number'); | |
} | |
}); | |
app.get('/beep', function(req, res){ | |
var ms = parseInt(req.query.t) || 200; | |
b.digitalWrite('P9_42', b.HIGH, function(){ | |
setTimeout(function(){ | |
b.digitalWrite('P9_42', b.LOW); | |
}, ms); | |
res.end('ピーーー'); | |
}); | |
}) | |
app.listen(8123, function(){ | |
console.log('Server listening on port 8123.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment