board.on("ready", function() { var proximity = new five.Proximity({ controller: "HCSR04", pin: 7 }); proximity.on("data", function() { console.log("Proximity: "); console.log(" cm : ", this.cm); console.log(" in : ", this.in); console.log("-----------------"); }); proximity.on("change", function() { console.log("The obstruction has moved."); }); });
pingBoard.on("ready", function() { const sonar = new j5.Proximity({ controller: 'HCSR04', pin: 'A0' }); sonar.on('data', function() { if (this.cm > 20 && !moving) { console.log(`can not see anything at ${servoPos} moving along`); if (stepInterval > 0) { if (servoPos < POS_MAX) { stepServo(); } else { stepInterval = -1 * stepInterval; stepServo(); } } else { if (servoPos > POS_MIN) { stepServo(); } else { stepInterval = -1 * stepInterval; stepServo(); } } } }); });
pingBoard.on("ready", function() { const sonar = new j5.Proximity({ controller: 'HCSR04', pin: 'A0' }); sonar.on('data', function() { if (this.cm < 20 && !moving) { if (servoPos === (POS_MAX+POS_MIN)/2) { servoPos = POS_MAX; } else if (servoPos === POS_MAX) { servoPos = POS_MIN; } else { servoPos = (POS_MAX+POS_MIN)/2; } console.log(`blocked..moving to ${servoPos}`); moveServo(servoPos); } }); });