PCA9685 for LED strips - Gamma correction?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- timfield
- Posts: 8
- Joined: Fri Mar 29, 2013 3:21 pm
PCA9685 for LED strips - Gamma correction?
So I've got Adafruit's PCA9685 12-bit PWM driving multiple LED strips quite nicely. But I'm wondering how to apply the 8-bit Adafruit Gamma Correction Table (https://learn.adafruit.com/led-tricks-g ... -quick-fix) to this 12-bit controller?
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: PCA9685 for LED strips - Gamma correction?
You could make a 4096-entry table, but it's probably easier to do something like:
The gamma table is basically a list of scaling factors, and dividing each entry by 256 gives you a fraction you can apply to any value.
Shift your 12-bit PWM value right four bits to get an index into the table, then use that value as your scaling factor.
Code: Select all
int pwmLevel; // original 12-bit value for the PCA9685
int output = ( pwmLevel * gamma[ pwmLevel >> 4 ] ) / 256;
Shift your 12-bit PWM value right four bits to get an index into the table, then use that value as your scaling factor.
- timfield
- Posts: 8
- Joined: Fri Mar 29, 2013 3:21 pm
Re: PCA9685 for LED strips - Gamma correction?
Okay, thanks... will give that a try!
Please be positive and constructive with your questions and comments.