Ir Switch counter

Hello,

I have 8 IR range finders. They are arranged 2 per door. I want to be able to tell if someone has entered or exited the room.
If they are entering the first IR will change range then the second (within an elapsed time). roomcount++ -> turn lights on
If they are leaving the second IR will change then the first roomcount --
-> turn lights off.
My problem is I am updating the code every second to coniside with the rest of the program. Do I need to split this into 2 arduinos or can I handle it somehow. The other code is my period for the lights (rgb lighting).
I know how to do this in ladder logic but c+ is a little different :stuck_out_tongue:

if range change -> start timer + latch timing bit -> second range change -> do work etc.

Can someone help me out?

Thanks,
Ram

You could use this library: Arduino Playground - TimedAction Library and have two protothreads operate on each task.

One could check for door in/out, and the other could handle the RGB lighting
:slight_smile:

That seems like it is the right path. I havn't done c/c+ since junior high 11 years ago. It's wierd as you get older looking back at how smart you actually were younger and not using it :/. I thought back then was trivial stuff and now I look at some of my old projects and its actually kinda cool. Oh well. UTILISE YOUR TALENTS YOUNGE ONES!!!