No I am talking about different levels of light per LED, not all LEDs...
If we look back at that schematic prins made. We're using the column pin from the switch matrix to also determine which column of LED to choose from. And with the LED Row pins we can apply PWM to set intensity of the LED at (Col,Row).
Tho Im not sure if the teensy has enough pins that can do PWM.
Well I wasn't sure about whether it gave enough control over the PWM to be able to do it in hardware, but actually I think it might.
Timer 2 could be used to run a timebase for the columns at a few kHz.
Timers 1 and 3 can be set to do 8-bit PWM, and have 3 PWM outputs each. Timer 0 is 8-bit anyway, and has 2 PWM outputs.
So each time the column interrupt fires, the handler would do something like...
- disable PWM outputs
- disable column n
- update PWM output compare values
- enable column n+1
- enable PWM outputs
- read keys
Since the column updating forms part of the PWM, any jitter in handling it would result in varying light levels. This would have to be minimised.
The PWM channels should run at some multiple of the column scan frequency. At 16MHz clock and 8 bit resolution they would be running at 62.5kHz. Dividing that by 16 gives roughly 4 kHz, which sounds about right. That would be divided again by the number of columns to get the overall matrix scan frequency, and that wants to be high enough that you don't notice flicker in the LEDs.