Hello community. As most of the topic starts here - I'm kind of new to Arduino and in programming in general or if not that new at least with basic knowledge. Yet I'm working on very simple project which sometimes looks very complicated to me.
General idea - smart barrier - computer vision software scan and verifies vehicles plate IDs. If it's not blacklisted (MySQL) it lifts the barrier. The application I did on VB.NET and the above works just fine. Now at the final stage I'm adding some additional controls and in particular with my question - 2 IR obstacle sensors. One (s1) under the barrier preventing closing if something is under and the second one (s2) a little after s1 to open the barrier if a vehicle is exiting (no exit control, only entering) and to detect if the direction is 'In' or 'Out'. That last part is where I'm bumping.
Somehow I need to realize the code where: If first (s1==HIGH) and then (s2==HIGH) then the direction is 'In'. Otherway around would be 'Out'.
Being under 'loop' completely messes my thinking... How to ask Arduino which of these 2 events has happened first in timely manner? Is it even possible?
And the second part - I need this "Out" flag to be 'Serial.Write'en so my VB application can read it and set the direction into the MySQL table. As all the rest of the VB-Arduino connection is in the direction VB to Arduino and for every case I use 'Serial.Open()', sent, 'Serial.Close()', do I need such opening and closing for the direction Arduino to VB? With only Serial.Write will it jam the port for eternity? Because VB does if not .Close().
I know I probably write not very understandable but I'd appreciate if anyone has any idea how to execute this. It just sounds so simple and yet it's bugging me so hard.
Thank you in advance.