Light Sculpture: Pulse Width Modulation #3

Home

Current Objective: Visible Pulse Width Modulation

  1. Read the potentiometer knob voltage using analogRead
  2. Modulate the duty cycle (onTime) of the LEDs using the knob voltage.

Requirements

  1. Cleanly format your code to maximize organization and readability like the dpeaArduinoStyleGuide.
  2. Clarify the purpose of each function and variable through smart naming.
  3. Use headers and comments as needed to enhance organization.

Pulse Width Modulation (Calculating On Time)

  1. Open the definition of getOnTimeUsingKnob, which returns an int (so it's an int, not void function) with the statement .
  2. Update the knob voltage by calling a function named updateKnobValue using the statement .
  3. Declare the float variable knobRatio and assign it to be the ratio of knobValue to maxKnobValue using the statement .
  4. Declare the int variable onTime and assign it to be the product of knobRatio and the pwmPeriod using the statement .
  5. Return the onTime using the statement .
  6. Add a new function definition named updateKnobValue that opens with the statement (hint: it is a void function with no parameters).
  7. This function assigns the knobValue by reading the voltage on the knobPin using the statement (hint: do NOT redeclare the knobValue, as it is global).
  8. Test your code by uploading it, turning the knob, and observing the results.
Back Next Page