Simplifying triangle wave implementation