Help writing code(Spin)
msiriwardena
Posts: 301
in Propeller 1
Hello all,
How do one write code for a variable say "Pressure" value of which changes continuously fluctuating between 5 and-15.
If the fluctuations remains between remains between 3 and -5 for over 5 seconds, then I would like to some thing, if not do nothing.
Thanks for your help
Siri
How do one write code for a variable say "Pressure" value of which changes continuously fluctuating between 5 and-15.
If the fluctuations remains between remains between 3 and -5 for over 5 seconds, then I would like to some thing, if not do nothing.
Thanks for your help
Siri
Comments
Untested, so use at your own risk.
-Phil
-Phil
That is very elegant fix,I will use it my machine.
I gave it shot(amateur programming) please can you see whether it works if not correct me.
I have attached the code.
Thank you.
Siri
When the machine is working properly the pressure readings are 6 to -8
when it malfunctions the readings are 1 to -2.
I need to fix this malfunction in about 5 sec. if the malfunction remains > 5 sec.
So if the pressure readings self corrects within 5sec - no fix is needed and the fix is necessary only if the
malfunction continue for greater than 5 sec.
Is the code snippet you suggested will take care of this issue.Will this code work if the malfunction self corrects?
Thanks for the help.
Siri
If your pressure falls within the range you want to monitor the value in check is incremented; when this value is equal to five seconds of the issue, then do_something is called. If the pressure is not in that range, check is cleared.
I also learned something new.
Thanks again for helping the amateurs.
Siri
From the very first line your code will stop executing if Pressure1 is not equal to 0 or -1.
"delay(1)" is not defined anywhere.
"X" never gets beyond 1 because the first instruction in that repeat loop clears X back to zero.
"if X => 9" Is a conditional statement which should be followed by an indented line that will only be executed if that condition is true. (You have already said "Repeat 9".)
There are syntax errors as well as logical errors.