Skip to content

Instantly share code, notes, and snippets.

Created March 1, 2016 13:16
Show Gist options
  • Save anonymous/32672c538e020c705f25 to your computer and use it in GitHub Desktop.
Save anonymous/32672c538e020c705f25 to your computer and use it in GitHub Desktop.
var m = require('mraa'); //IO Library
var http = require('http');
var express = require('express');
var app = express();
var server = http.createServer(app);
app.use(express.static('static'));
var io = require('socket.io')(server); //Socket.IO Library
var blinkInterval = 1000; //set default blink interval to 1000 milliseconds (1 second)
var blinkStatus = false;
var ledState = 1; //set default LED state
var point_Alpha = 0 ;
var myLed = new m.Gpio(17); //LED hooked up to digital pin 13
myLed.dir(m.DIR_OUT); //set the gpio direction to output
///////////////////////////////////////////////////
///////// Express Server //////////////////////////
///////////////////////////////////////////////////
app.get('/play.html',function(request, response){ //...............URL... "/" ...HTTP GET......
response.sendFile(__dirname + '/play.html');
});
app.get('/intro.html',function(request,response){
response.sendFile(__dirname + '/intro.html');
});
app.get('/',function(request,response){
// response.sendFile(__dirname + '/testGet.html');
response.sendFile(__dirname + '/index.html');
});
server.listen(8080,'0.0.0.0',function(){
console.log('HTTP............ http://127.0.0.1:8080/ .........');
});
///////////////////////////////////////////////////
////////// Socket.io Streaming ////////////////////
///////////////////////////////////////////////////
var exec = require('sync-exec')
io.on('connection', function(socket){
socket.on('changeBlinkStatus',function(data){
console.log("Status:" + blinkStatus );
blink();
});
socket.on('pointer',function(data){
point_Alpha = data;
//console.log(parseFloat( point_Alpha)/100);
exec('python v_servo.py '+ parseFloat(point_Alpha/400) , 1000)
});
socket.on('error', function(data) {
console.log('error', data);
});
});
///////////////////////////////////////////////////
////// GPIO Controller ////////////////////////////
///////////////////////////////////////////////////
//blink(); //start the blink function
function blink(){
blinkStatus = !blinkStatus;
// ledState = !ledState;
myLed.write(blinkStatus ? 1: 0); //write the LED state
// ledState = 1 - ledState; //toggle LED state
// setTimeout(blink,blinkInterval); //recursively toggle pin state with timeout set to blink interval
}
function servo(){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment