I am working with two potentiometers and saving the position as Pot1Val and Pot2Val. I use LocalWord as variable storage. Pot2Val is the master value and Pot1Val determines how much above and below Pot2Val the Pot1Val will be set.
Most of the time it works well, but in certain cases the result drops below one and becomes 65535. I thought that using the "MIN 1" code would keep that from happening, but it does not.
IF Pot1Val = 1 and Pot2Val = 482 then
LocalWord = 482
Pot1Val = 482
Pot2Val = 1 (good result)
BUT if Pot1Val = 1 and Pot2Val = 481 then
LocalWord = 482
Pot1Val = 481
Pot2Val = 65535 (bad result, Pot2Val must remain at 1 or above)
What is wrong with my code??
Most of the time it works well, but in certain cases the result drops below one and becomes 65535. I thought that using the "MIN 1" code would keep that from happening, but it does not.
IF Pot1Val = 1 and Pot2Val = 482 then
LocalWord = 482
Pot1Val = 482
Pot2Val = 1 (good result)
BUT if Pot1Val = 1 and Pot2Val = 481 then
LocalWord = 482
Pot1Val = 481
Pot2Val = 65535 (bad result, Pot2Val must remain at 1 or above)
What is wrong with my code??
Code:
SERTXD("P1&P2 ",#Pot1Val," ",#Pot2Val," ") 'show starting values
IF Pot1Val > 482 AND Pot1Val < 542 THEN
Pot1Val = Pot2Val
ELSEIF Pot1Val < 483 THEN
LocalWord = 483 - Pot1Val MIN 1
Pot1Val = Pot2Val
Pot2Val = Pot2Val - LocalWord MIN 1
ELSE
LocalWord = Pot1Val - 541 MIN 1
Pot1Val = Pot2Val - LocalWord MIN 1
ENDIF
SERTXD("LW, P1&P2 ",#LocalWord," ",#Pot1Val," ",#Pot2Val,cr,lf) 'show result of manipulation