using optical gates to count how many peapole are in a room with(b83609)

That's possible, of course. But before that you should implement the state machine, which is the base for all further actions.