servo test

parent fa3d7fa4
Showing with 29 additions and 34 deletions
......@@ -8,47 +8,42 @@ var Gpio = require('pigpio').Gpio;
GPIO
*/
var RED = new Gpio(4, {mode: Gpio.OUTPUT});
var GREEN = new Gpio(17, {mode: Gpio.OUTPUT});
var BLUE = new Gpio(27, {mode: Gpio.OUTPUT});
// Valor de puerta cerrada 1850
// Valor de puerta abierta 950
// La amplitud de apertura es 900 (90 grados)
// Tiempo para la apertura: 10s
var motor = new Gpio(13, {mode: Gpio.OUTPUT});
// Inicializacion de pines
var RED = new Gpio(4, { mode: Gpio.OUTPUT });
var GREEN = new Gpio(17, { mode: Gpio.OUTPUT });
var BLUE = new Gpio(27, { mode: Gpio.OUTPUT });
var motor = new Gpio(13, { mode: Gpio.OUTPUT });
// Puerta cerrada:1850
// Puerta abierta: 950
// Rango apertura: 900
var pulseWidth = 1850;
var increment = -10;
motor.servoWrite(pulseWidth);
// Apertura y cierre continuo
/*setInterval(function () {
motor.servoWrite(pulseWidth);
for(var i=0;i<90;i++){
setTimeout(function(){openFunct();}, 100);
pulseWidth += increment;
if(pulseWidth > 950){
console.log("Fuera de rango en apertura");
break;
if (pulseWidth >= 1850) {
increment = -10;
} else if (pulseWidth <= 950) {
increment = 10;
}
}
function openFunct(){
motor.servoWrite(pulseWidth);
pulseWidth += -10;
}
/*var test = setInterval(function () {
motor.servoWrite(pulseWidth);
}, 100);*/
pulseWidth += increment;
// Apertura
var apertura = setInterval(function () {
motor.servoWrite(pulseWidth);
if (pulseWidth >= 1850) {
increment = -10;
} else if (pulseWidth <= 950) {
increment = 10;
}
if (pulseWidth >= 1850) {
increment = -10;
} else if (pulseWidth <= 950) {
clearInterval(apertura);
}
}, 100);*/
}, 100);
// Clean LEDs
//RED.pwmWrite(dutyCycle);
......@@ -60,7 +55,7 @@ function openFunct(){
WEB SERVER
*/
app.use('/public', express.static(__dirname + '/public'));
app.get('/', function(req, res) {
app.get('/', function (req, res) {
res.sendFile(__dirname + '/views/index.html');
});
server.listen('8080');
......@@ -72,7 +67,7 @@ server.listen('8080');
var estadoPuerta = 0; //cerrada
io.sockets.on('connection', function(socket) { // WebSocket Connection
io.sockets.on('connection', function (socket) { // WebSocket Connection
console.log("Cliente conectado");
......@@ -80,7 +75,7 @@ io.sockets.on('connection', function(socket) { // WebSocket Connection
socket.emit("inicializacion", Number(estadoPuerta));
//Escucha la orden del cliente
socket.on('emisionOrden', function(data) { //get light switch status from client
socket.on('emisionOrden', function (data) { //get light switch status from client
var ordenRecibida = data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment