For ‘the challenge’ , I set out to control multiple ‘devices’ via Shift Registers.

I wanted to see if I could control each device with PWM throught the SRs.

And yes, I could

However, my approach does have limitations.

I have an array that holds a ‘power’ value each device.

Then …

loop() {

if(power_value_of_the_bit < counter){turn bit off}

counter++

if (counter>limit){counter=0}

}

…and indeed, this works well so far with power levels 0-50, 2SRs & 8 ‘devices’.

Problem is, for a power level of 25 out of 50, I am actually sending 25 ONs, followed by 25 OFFs.

That delay (25 continuous OFFs), is now limiting how expandable the system will go.

e.g. if I want 100 power levels, or control other devices that require/benefit from more constant signals.

The ideal situation would to alternate, ON then OFF, 25 times.

I thought I had this sorted, until I did the maths.

(I’ll use power values up to 100 now to make reading easier)

Power 80, would mean turning the bit off on iteration every 5. [100/(100-80)=5]

And that is very doable by looking at when the iteration counter is exaclty divisible by 5.

But then when we look at a power of 60, I need to turn bits off every 2.5 iterations !

Well I sat with Excel for hours, trying to work out the maths of how to add in the adjustments … then smoke started coming out of my ears and setting the smoke alarms off!

I MUST be missing something obvious here ?

Or am I asking too much of this type of setup ?

I’d be grateful of any maths insight, or strategy hints, that might help me get a little futher, or indeed - - tell me ‘no’ !

Many Thanks

Notes:

Happy to post actual code if required, but atm I am seeing this as more of an ‘academic’ question than literal.

‘Devices’ : yes atm they are LEDs, but it is the technique of mastering Shift Registers/PWM that is the real focus here. (LEDs are just easy to use for testing.)