Alternatively make a lookup table of input value to output bitmask - it costs more in memory (which isn't normally a limit on a Pi), but is faster to lookup. Either method also allows you to apply non-linear representations to your bargraphs - switch between a virtual LM3914, LM3915, and LM3916 at ...