FSM for a people in room counter in C/Arduino and diagram
<p>First of all, excuse me if this isn't the right site to post this question but  I didn't know where to ask this.</p>

<p>I need to implement a FSM to represent a counter of people in a room, there are two possibilities,people can enter the room or leave the room. An empty room is guaranteed at the beginning and only one person can go through the door at one time.</p>

<p>To know wheter a person enters or leaves, there are 2 sensors A and B, which depending on the order of activation indicate if a person is entering or leaving. A then B indicates a person enters the room, B then A indicates a person exits the room.</p>

<p>Now, I have to implement this on arduino and make the FSM diagram but I'm having problems figuring out the diagram, even though I think I already got the C program right (haven't tested it)</p>

<p>So, basically here's part of my C/Arduino program</p>

<pre><code>int currentPeople = 0;
PeopleState currentState = None;
enum PeopleState {
 A,
 B,
 None
};
</code></pre>

<p>Now these are two functions that get called for their respective sensors</p>

<pre><code> //Gets called every time sensor A is activated
 void countPeopleA(){
    if (currentState == None){
       currentState = A;
    } else if (currentState == B){
       if(currentPeople &gt; 0){
           currentPeople--;
       }
       currentState = None;
    }
 }
 //Gets called every time sensor B is activated
 void countPeopleB(){
     if (currentState == None){
         currentState = B;
     } else if (currentState == A){
         currentPeople++;
         currentState = None;
     }
 }
</code></pre>

<p>My concerns are these:</p>

<ul>
<li>Are the states I defined correct for the problem? I mean, defining a state for whenever a sensor is activated is right or should the states be Entering and Leaving?</li>
<li>How can I diagram the states? I'm just learning about FSM so I have problems figuring it out, like how can you guarantee that if the room is empty a person doesn't leave? I can check for that condition in code but I don't know how to represent it.</li>
</ul>