Skip to content

Commit

Permalink
Fixed overlow bug in new input conditioning code
Browse files Browse the repository at this point in the history
  • Loading branch information
clone45 committed Aug 7, 2014
1 parent 66e5255 commit 8e0d25f
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions ModuleAnalogInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,32 @@ uint32_t ModuleAnalogInput::read()
// due to tolerance issues. This code adjust the input to give us a little
// wiggle room to get the full range. However, as a side effect, it reduces
// the overall knob range.
//
// The map(..) function below can return negative values. It's important
// to constrain those right away. Don't try to assign those negative numbers
// the this->value, which is unsigned and will overflow.

map(this->value,10,4095,0,4095);
this->value = constrain(this->value,0,4094);
this->value = constrain(map(this->value,10,4095,0,4095),0,4094);

/*
if(this->pin == PIN_PRG)
{
Serial.print("PRG: ");
Serial.print(this->value);
}
if(this->pin == PIN_SR)
{
Serial.print(" SR: ");
Serial.print(this->value);
}
if(this->pin == PIN_MOD)
{
Serial.print(" MOD: ");
Serial.println(this->value);
}
*/

return(this->value);
}
Expand Down

0 comments on commit 8e0d25f

Please sign in to comment.