I am developing a C# application which is supposed to receive data from a Neurofeedback software and transmit it to a Lego NXT brick. Everytime a certain goal is reached inside the Neurofeedback Software, the Software transmits through a TCP socket to the C# application the value 1, and if the goal isn't reached, then it sends 0 to C#. Then, the C# application sends the information to my NXT car (using a bluetooth communication): if the NXT receives 1, it should move; if it receives 0, then it should stop immediately.
Since sometimes these values change on a very short period of time, the NXT is not being able to respond that quickly and precisely (by moving or halting its movement). For instance: when it changes from 1 to 0 and then to 1 again, if the range period between the 1's is too short, then it will give the impression that the NXT is always moving.
In order to solve this problem, one solution would be to program a "timer counter": basically, in order for the NXT to move, then the goal (inside the Neurofeedback Software) should be obeyed for at least 1 second (that is, without interruptions - values changing from 1 to 0). In other words, if the C# application receives the value 1 without changing for at least 1 second (or more), then it should order the NXT to finally move (and to keep moving while C# does not receives a 0 value).
I know there is a timer feature on Windows Forms, but I couldn't manage to program a "counter" from it. Also, I tried to do some research as well, but I am starting to believe that maybe "timer counter" isn't the best way to describe what I am looking for...
Note: there is no code inside my NXT brick. Basically, the C# application (through a specific library) transmits all the movement commands to the NXT robot.
How about you keep the last N commands and see if there was any 0 in a range of Y and if there was you stop the movement?
In other words, assume moving forward as the default state and keep track of how many stops (0) you got in the last N commands. If it passes a threshold (that you will define) it stops and only starts again if receives another set of N 1 commands.
Time is probably not the dimension you need here, but if you do, you could probably apply the same logic I described inside a timer.
Keep all the last N commands you received and make it default to move forward. Then, create a timer and on every tick, you check the commands you got and decide if you have to keep moving or stop.