BioAmp-EXG-Pill
BioAmp-EXG-Pill copied to clipboard
Claw constrain and arithmetic overflow fix
- Using
constrain
to guarantee servo angles are valid and between the desired 90 to180 (inclusive) range. - Enlarging
sum
variable to avoid overflow, nowint32_t
(frominttypes.h
) - Adding some explcit (tradtitional C style) casts for
float
conversions. - Converted
getEnvelop()
to return float and using a locally definedmapf
for improved conversion resolution.
Tested on the Arduino Uno (from pro kit). And on an Uno R4 WiFi as I happened to have it plugged in.
Fixes #38.
I was thinking about float
for getEnvelop()
and use of mapf
. This will change how the servo reacts - my testing so far has been without servo attached. The current integer code may have a slightly unintentional effect of smoothing the movement of the servo due to the effective quantisation and small number of values, e.g. if value is varying between certain values with a <1.0 range these can all map to N degrees setting and servo will settle not make any small movements.
Worth testing with a real setup using a servo to see how it behaves.