On Github interactive-object / francejs
Passerelle entre les mondes physique et virtuel
$(function(){ var socket = new Websocket('ws://raspberry.local/websocket/socket'); // forward button $(".forward").touchStart(function(){ socket.send("forward"); }).touchEnd(function(){ socket.send("brake"); // backward button $(".backward").touchStart(function(){ socket.send("backward"); }).touchEnd(function(){ socket.send("brake"); }); });
$ npm install expressjs serialport websocket
var app = express(), WebSocketServer = require('websocket').server, serial = new SerialPort("/dev/ttyAMA0", { baudrate: 57600}); var socket = new WebSocketServer({ httpServer: server }); socket.on('request', function (s) { var connection = request.accept(null, request.origin); connection.on('message', function (message) { if (message == "forward") serial.send('forward'); else if (message == "backward") serial.send('backward'); }); });
int ENA=6;// pin 5(output pwm) int IN1=4;//pin 2 int IN2=5;//pin 3 void loop(){ if( Serial.available() ){ // if data is available to read val = Serial.read(); delay(10); // delay 10 milliseconds to allow serial update time if (actionEqual("forward")==0){ // max speed analogWrite(ENA,255); // IN1 to High and IN2 to Low run the motor en forward digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); } } }