I have not followed all details of this thread.
As a general hint: as a first step:
You should describe the desired functionality in normal words with avoiding any programming-terms.
As a not so experienced programmer you might have misconceptions of how the code works. Using normal words ensures to keep out misunderstandings.
The description should have typical example-data as written characters or digits
So a rough sketch of such a description applied to your case would look like that
over serial interface a sended "A" is received.
voltage is measured 1,87V
No the code shall check if
- first condition .... written in normal and precise words
- second condition ....written in normal and precise words
if these two conditions are true and only if these two conditions are true
the following conditions shall be checked:same kind of description as above.
precise words mean avoid generalising words like "the value" "that" etc.
always repeat the descriptive word
not "the value"
but "the voltage of temperatur-sensor top-temperature"
not "the adc-reading"
but
"the ADC-value of temperatur-sensor bottom-temperature"
etc.
This gives a clear picture about the desired functionality.
Using state-machines can reduce the number of if-conditions a lot, because the mutual exclusiveness of code-execution inside a state-machine reduces what code gets executed.
So my question is: did you understand the fundamental principle of state-machines?
best regards Stefan