I am trying to make a custom PWM script to work with my Charlieplexed series of LEDs. However, I am struggling to make certain intensity values look smooth with no flashing. Different brightness values will have the LED on for a different amount of ticks. In order to make it feel smooth, I need to optimize the spacing of on and off ticks for the LEDs but I can quite figure out how to do so.
If you have a pattern that has x amount of booleans and n amount of them are true, how would you go about equally spacing out the trues as much as possible?
Here is an example of what I am looking for:
x = 10, n = 7
Desired result: 1,1,1,0,1,1,0,1,1,0
x = 10, n = 4
Desired result: 1,0,1,0,0,1,0,1,0,0