Forgot the interval.cancel(): On Wednesday, August 19, 2015 at 11:28:41 PM UTC+2, Zlatko wrote: > > > So let's write it: > > function doorInMotion (err) { > // now is the trick. We want to check every second if the door is open. > If yes, write a zero to opendoor pin, so that we stop the engine. > // we do this every second, and we save this interval. > > var interval = setInterval(function() { // this inner function runs > every second, until somebody calls the interval.cancel(); > > // every second, check the door sensor. > gpio.read(DOOROPEN, function(err, value) { > if (err) { > console.log('Error reading door-open value.', err); > return; // also could be a good idea to stop the engine here, > because due to error, we don't know if the door is open or not, maybe > sensor has failed. > } > // anyway, if the sensor didn't fail, we can check the DOOROPEN pin > value: > if (value !== true) { > console.log('Door not yet open, keep the motor running.'); > } else { > console.log('Door is finally open.'); > // now stop the door >
And stop the interval here too: clearInterval(interval); > gpio.write(OPENDOOR, false, function(err) { > if (err) {console.log('Error stopping the door motor.', err); > }); > } > }); > }, 1000); > } > >> >> -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. To post to this group, send email to nodejs@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/da75c2ac-7915-47ed-a09e-09539f92954b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.