Night Light Mode: Gamma Correction

Home

Current Objective: Use Gamma Correction to Improve the Fade

Requirements

  1. Ensure you understand each step before moving on.
  2. Write code for each step as you go.
  3. Cleanly format your code.
  4. Test your code at the end of each page.

Using Gamma Correction

Test the Night Light Mode and notice the brightness is saturated: it is so bright that there is hardly any visible changes for the last 25% of knob travel in Night Light Mode.

Read this resource on Gamma Correction.

The pow(base, exponent) function raises the base to the exponent power.

It is built-in to the math library. More details are available here.

In the Global Variable Declarations (Nouns):

  1. Increase the pwmPeriod to 10000 so that the statement is now
  2. Test this change to see the effect of increasing the dynamic range of the PWM by increasing the possible range of onTime.
  3. Declare a const float variable named gamma and assign it to be 3.0 with the statement

In the definition of getOnTimeUsingKnob, after declaring knobRatio:

  1. Declare a float variable named fractionOn and assign it to be the return value of gammaCorrect on knobRatio with the statement
  2. Replace the knobRatio with the fractionOn in the declaration of onTime so that the statement is now

In the Section of Knob Functions:

  1. Open the definition of gammaCorrect (hint: check your Function Declarations) with the statement
    1. Declare a float variable named product and assign it to be the result of raising the ratio to the gamma power with the statement (Remember to use the pow function described at the top of the page.)
    2. Return the variable product with the statement

Make sure you test your code!

Change gamma and see the result.

Back Next Page