Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
board.on('ready', function() {
const proximity = new five.Proximity({
controller: PiIO.HCSR04, // Custom controller
triggerPin: 'GPIO23',
echoPin: 'GPIO24'
});
proximity.on('change', function() {
console.log('cm: ', this.cm);
});
});
board.on("ready", function() {
//Create new Ping and show distance on change
var ping = new five.Proximity({
pin: 7,
freq: 200,
controller: "HCSR04"
});
var piezo = new five.Piezo(11); // leostick piezo
var intervalID = 0;
ping.on("change", function( err, value ) {
console.log('Object is ' + this.cm + ' cm away');
// now we do a callback on the interval of the centimetres thus
// shorter centimetres means less interval before calling the tone command
clearInterval(intervalID);
if (this.cm > 4) { // this is arbitrary to stop the conflicts with tone.
board.on('ready', function() {
var proximity = new five.Proximity({
controller: 'HCSR04',
pin: 7 // Digital pin 7
})
proximity.on('data', function() {
console.log(this.cm + ' cm at ' + new Date())
// noisy data? You can use a smoothing algorithm:
// http://stackoverflow.com/a/3761318/496797
})
})
board.on("ready", function() {
var left_wheel = new five.Servo.Continuous(9);
var right_wheel = new five.Servo.Continuous(8);
var controller = new Controller({
left: left_wheel,
right: right_wheel,
lstop: 90, // use these to set the stop value of the servo
rstop: 90,
});
// Create new Ping and use to avoid collisions.
console.log('Initialising Range Finder');
var ping = new five.Proximity({
pin: 10,
freq: 200,
controller: "HCSR04"
});
ping.on("change", function( err, value ) {
if (this.cm < range) {
console.log('WARNING: Collision avoidance activated at: ' + this.cm + ' cm');
left_wheel.to(controller.LSTOPVAL);
right_wheel.to(controller.RSTOPVAL);
}
});
});
board.on('ready', function() {
const proximity = new five.Proximity({
controller: 'HCSR04',
pin: 'GPIO25'
});
proximity.on('data', function() {
console.log('cm: ', this.cm);
});
});
board.on("ready", function() {
//Create new Ping and show distance on change
var ping = new five.Proximity({
pin: 8,
controller: "HCSR04",
freq: 200,
});
ping.on("change", function( err, value ) {
console.log('Object is ' + this.cm + ' cm away');
console.log('Object is ' + this.inches + ' inches away');
});
});
board.on("ready", function() {
var proximity = new five.Proximity({
freq: 1000,
controller: "HCSR04",
pin: 10
});
proximity.on("data", function() {
console.log("inches: ", this.inches);
console.log("cm: ", this.cm);
});
});