First I want to say thank you for posting this.. and secondly I want to say
sorry for not replying back to you so late. I have been tied up with
another project, bathroom renovation, which has kept me frustrated.
Anyways, I have come to understand javascript and node callback functions
much better. Still learning though and your code example has helped me so
much. It isn't working yet but I am sure I will get the bugs figured out
with some time. Once I do I will post back.. can't say thank you enough
for the example.. helped my lightbulb in my brain go on.
On Wednesday, August 19, 2015 at 7:08:58 PM UTC-5, Zlatko wrote:
>
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/b200df54-5a27-4294-8695-5def76a44465%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.