essentially a copy of LED dimmer code