C++ while loop with a conditional statement. Read an input and skip every three times before taking action.

New to this, your help please anyone. Thanks.

Extract below read's pressure value A. If it's 200000, B is actioned. However, pressure follows a sign wave fluctuating between 100000 and 200000, need to skip A=200000 every THREE times and then action B.

IS there a simple one line statement which can read A=200000, action B, then skip the next A=200000 THREE times and then action B. The loop continue in while statement.

[code]
"
"
Int main ();
{
While (1<q<500)
{
if A=200000 THEN //*
B=300;
else if A=100000 THEN
B=310;
}
end_f_loop(f,th)
}
> Extract below read's pressure value A. If it's 200000, B is actioned.
> However, pressure follows a sign wave fluctuating between 100000 and 200000
Are you working with some idealised sine wave that's guaranteed to hit 100000 and 200000 every cycle?

Or are you dealing with real sensors with noise?
https://www.semanticscholar.org/paper/Fuzzy-PID-tracking-performance-for-ball-and-beam-Tajjudin-Aziz/1a9eda16b8f3a0457a4167312222c77b71c6ea9f/figure/11
Where you're not guaranteed to always hit the limit each time, or you might get multiple samples in a very short interval.

https://en.wikipedia.org/wiki/Hysteresis#In_engineering

Your code is nowhere near being valid C++, so it's of little use in understanding your question.

> then skip the next A=200000 THREE times and then action B.
https://en.wikipedia.org/wiki/Finite-state_machine
You have two states, one for performing the action, and another for counting the interval.

Or even a simple counter
1
2
3
4
if ( A ) {
    if ( count == 0 ) do B
    else count = ( count + 1 ) % 4
}



Topic archived. No new replies allowed.