servo test

parent f232f218
Showing with 21 additions and 15 deletions
...@@ -17,32 +17,37 @@ var motor = new Gpio(13, { mode: Gpio.OUTPUT }); ...@@ -17,32 +17,37 @@ var motor = new Gpio(13, { mode: Gpio.OUTPUT });
// Puerta abierta: 950 // Puerta abierta: 950
// Rango apertura: 900 // Rango apertura: 900
var pulseWidth = 1850; var pulseWidth = 1850;
var increment = -10;
// Apertura y cierre continuo // Abrir puerta
/*setInterval(function () { function abrirPuerta(){
motor.servoWrite(pulseWidth);
pulseWidth += increment; var increment = -10;
if (pulseWidth >= 1850) { var intervaloApertura = setInterval(function () {
increment = -10;
} else if (pulseWidth <= 950) { motor.servoWrite(pulseWidth);
increment = 10;
} pulseWidth += increment;
if (pulseWidth <= 950) {
clearInterval(intervaloApertura);
}
}, 100);
}
}, 100);*/ // Cerrar puerta
function cerrarPuerta(){
var increment = 10;
// Apertura
function abrirPuerta(){
var intervaloApertura = setInterval(function () { var intervaloApertura = setInterval(function () {
motor.servoWrite(pulseWidth); motor.servoWrite(pulseWidth);
pulseWidth += increment; pulseWidth += increment;
if (pulseWidth >= 1850) { if (pulseWidth >= 1850) {
increment = -10;
} else if (pulseWidth <= 950) {
clearInterval(intervaloApertura); clearInterval(intervaloApertura);
} }
...@@ -50,6 +55,7 @@ function abrirPuerta(){ ...@@ -50,6 +55,7 @@ function abrirPuerta(){
} }
abrirPuerta(); abrirPuerta();
cerrarPuerta();
// Clean LEDs // Clean LEDs
//RED.pwmWrite(dutyCycle); //RED.pwmWrite(dutyCycle);
......
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