servo test

parent fa3d7fa4
Showing with 29 additions and 34 deletions
...@@ -8,47 +8,42 @@ var Gpio = require('pigpio').Gpio; ...@@ -8,47 +8,42 @@ var Gpio = require('pigpio').Gpio;
GPIO GPIO
*/ */
var RED = new Gpio(4, {mode: Gpio.OUTPUT}); // Inicializacion de pines
var GREEN = new Gpio(17, {mode: Gpio.OUTPUT}); var RED = new Gpio(4, { mode: Gpio.OUTPUT });
var BLUE = new Gpio(27, {mode: Gpio.OUTPUT}); var GREEN = new Gpio(17, { mode: Gpio.OUTPUT });
var BLUE = new Gpio(27, { mode: Gpio.OUTPUT });
// Valor de puerta cerrada 1850 var motor = new Gpio(13, { mode: Gpio.OUTPUT });
// Valor de puerta abierta 950 // Puerta cerrada:1850
// La amplitud de apertura es 900 (90 grados) // Puerta abierta: 950
// Tiempo para la apertura: 10s // Rango apertura: 900
var motor = new Gpio(13, {mode: Gpio.OUTPUT});
var pulseWidth = 1850; var pulseWidth = 1850;
var increment = -10; var increment = -10;
motor.servoWrite(pulseWidth); // Apertura y cierre continuo
/*setInterval(function () {
motor.servoWrite(pulseWidth);
for(var i=0;i<90;i++){ pulseWidth += increment;
setTimeout(function(){openFunct();}, 100);
if(pulseWidth > 950){ if (pulseWidth >= 1850) {
console.log("Fuera de rango en apertura"); increment = -10;
break; } else if (pulseWidth <= 950) {
increment = 10;
} }
}
function openFunct(){
motor.servoWrite(pulseWidth);
pulseWidth += -10;
}
/*var test = setInterval(function () { }, 100);*/
motor.servoWrite(pulseWidth);
pulseWidth += increment; // Apertura
var apertura = setInterval(function () {
motor.servoWrite(pulseWidth);
if (pulseWidth >= 1850) { if (pulseWidth >= 1850) {
increment = -10; increment = -10;
} else if (pulseWidth <= 950) { } else if (pulseWidth <= 950) {
increment = 10; clearInterval(apertura);
} }
}, 100);*/ }, 100);
// Clean LEDs // Clean LEDs
//RED.pwmWrite(dutyCycle); //RED.pwmWrite(dutyCycle);
...@@ -60,7 +55,7 @@ function openFunct(){ ...@@ -60,7 +55,7 @@ function openFunct(){
WEB SERVER WEB SERVER
*/ */
app.use('/public', express.static(__dirname + '/public')); app.use('/public', express.static(__dirname + '/public'));
app.get('/', function(req, res) { app.get('/', function (req, res) {
res.sendFile(__dirname + '/views/index.html'); res.sendFile(__dirname + '/views/index.html');
}); });
server.listen('8080'); server.listen('8080');
...@@ -72,7 +67,7 @@ server.listen('8080'); ...@@ -72,7 +67,7 @@ server.listen('8080');
var estadoPuerta = 0; //cerrada var estadoPuerta = 0; //cerrada
io.sockets.on('connection', function(socket) { // WebSocket Connection io.sockets.on('connection', function (socket) { // WebSocket Connection
console.log("Cliente conectado"); console.log("Cliente conectado");
...@@ -80,7 +75,7 @@ io.sockets.on('connection', function(socket) { // WebSocket Connection ...@@ -80,7 +75,7 @@ io.sockets.on('connection', function(socket) { // WebSocket Connection
socket.emit("inicializacion", Number(estadoPuerta)); socket.emit("inicializacion", Number(estadoPuerta));
//Escucha la orden del cliente //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; 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