I have a pressure sensor 0-30 PSI , and want to clamp the MAX value to 31 psi ( it has over range to about 35psi ) to protect my gauge , there is a stepper motor running a Pressure regulator and I use the feedback from the sensor in a closed loop , It will not clamp with the code I have ??? any ideas or did I do something stupid again lol ?
I am trying to control "psi" seek psi
PaulS:
You can't do that with software. You CAN constrain() the value that you read to be in some range.
Ok good to know !
int sensorValue0 = analogRead(A2); // sensor
int sensorValue1 = analogRead(A3); // pot
It is useless to read the pins AT COMPILE TIME.
The compiler doesn't know that anything is attached to some other computer.
**This came from code from another person ? I wondered about that because they are being called just after this**
( average.update( analogRead(0) ) );
(What's) (with) (the) (useless) (parentheses) (?)
**code from moving avg.h a library online so ??**
measurePressure();
That's a useless function, since it doesn't alter a global variable or return a value.
**Also from other coder ?**
if (abs(psi0) > 31.0 ) stepper.disable();// MAX output clamp
It's pointless to disable the stepper AFTER you've crashed the needle into the physical stop.
**the stop is about 35 psi so stopping at 31 will not crash it**
Next time around, you are just going to enable it again, and crash it again.
Again thanks for the reply , I will look up constrain
I tried several things , Im going to just switch the power to the stepper driver , it never seems to disable ? weird , so when it is at position power down the driver.
buzzkill:
I tried several things , Im going to just switch the power to the stepper driver , it never seems to disable ? weird , so when it is at position power down the driver.
But, you don't seem to have tried posting the COMPLETE code where you called constrain AND used the (constrained) value that it returns. Go ahead. Toss in the towel. I don't care. It's not my hardware that will be damaged.