simplified code to pick dimmer button label
simplified code to pick activated dimmer button
saved some local variables for readability
simplified target code
fixed target and activated calculations
the target is calculated based on the middle of upper and lower for the buttons that aren't on or off.  On and Off's targets are set to o and max, respectively.  The activated value for On and Off are based on if the value is 0 or max as well.