Skip to content

Commit

Permalink
Change the return value
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonPucheu committed Jan 19, 2023
1 parent 0d6b46e commit 06f5747
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Potentiometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ int Potentiometer::getValue()
int rawValue = getRawValue();
if (reversed)
rawValue -= rawValue * 2;
int finalValue;
if (rawValue < (rest + margin) && rawValue > (rest - margin))
finalValue = -1;
else if (rawValue < (0 + margin))
finalValue = -3;
else if (rawValue > (1023 - margin))
finalValue = -2;
else
finalValue = rawValue;
int finalValue = (rawValue - rest) * 2;
if (finalValue >= 1023 - margin) finalValue = 1023;
if (finalValue <= -1023 + margin) finalValue = -1023;
if (finalValue <= 0 + margin && finalValue >= 0 - margin) finalValue = -1023;
lastValue = finalValue;
return finalValue;
}

0 comments on commit 06f5747

Please sign in to comment.