ultrasonidos test

parent 65f5c994
Showing with 15 additions and 2 deletions
......@@ -18,8 +18,9 @@ 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 });
var trigger = new Gpio(23, {mode: Gpio.OUTPUT}),
var trigger = new Gpio(23, {mode: Gpio.OUTPUT});
var echo = new Gpio(24, {mode: Gpio.INPUT, alert: true});
var obstaculo = false;
var MICROSECDONDS_PER_CM = 1e6/34321;
......@@ -43,11 +44,18 @@ trigger.digitalWrite(0);
} else {
endTick = tick;
diff = (endTick >> 0) - (startTick >> 0); // Unsigned 32 bit arithmetic
console.log(diff / 2 / MICROSECDONDS_PER_CM);
if((diff / 2 / MICROSECDONDS_PER_CM) < 10.0){
obstaculo = true;
}else{
obstaculo = false;
}
}
});
}());
// Trigger a distance measurement once per second
setInterval(function () {
trigger.trigger(10, 1); // Set trigger high for 10 microseconds
......@@ -92,6 +100,11 @@ function cerrarPuerta(){
clearInterval(intervalo);
}
if(obstaculo){
clearInterval(intervalo);
abrirPuerta();
}
}, 100);
}
......
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