Charlieplexing a row of LED's

I'm just kind of curious why you're using charlieplexing for your original goal. If you have 4 groups of 6-10 LEDs, why not control each group off an I/O pin with a transistor to provide enough current? This will make your code trivial and charlieplexing 40 LEDs means you have a 2.5% duty cycle so may have a brightness issue.

Even if you want to control each LED individually, 40 LEDs only takes 13 IO lines for a normal matrix configuration (vs 7 to charlieplex) and you benefit from simpler code and better duty cycle. If you're that short on IO (which doesn't appear to be the case here), you can use a decoder or shift register to reduce your IO pin count.