Light Sculpture: Pulse Width Modulation #1

Home

Introduction

  • Write and test code as you go. This quiz is the guide. You must turn in your code
  • Refer frequently to the dpeaArduinoStyleGuide. Your architecture should follow the formatting shown there.

Setup

  1. Watch the following video on Pulse Width Modulation (PWM),stopping at 0:59 (one minute). Note that the electronics will be handled by our Arduino and LED Shield: Youtube.com
  2. Create a new folder in your Arduino folder named LightSculpture.
  3. Create a new sketch and save it in the LightSculpture folder as YourInitials_PulseWidthModulation.ino
  4. Copy and complete the following sketch template:
  5. 
    /* Light Sculpture Pulse Width Modulation - Written by - Updated */
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                         Function Declarations (verbs)                                              //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void pwmUsingKnob();
    
    void updateKnobValue();
    
    void turnOnArray( const byte arrayName[], const byte arrayLength);
    void turnOffArray(const byte arrayName[], const byte arrayLength);
    void turnOnAll();
    void turnOffAll();
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                         Global Variable Declarations (nouns)                                       //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                                Main Functions                                                      //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                                Knob Functions                                                      //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                                Helper Functions                                                    //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
  6. Move setup and loop into the Main Functions section.
  7. Copy the "Light Sculpture Helpers" function definitions from the previous exercise into the Helper Functions section.
  8. Open, read, and refer to the dpeaArduinoStyleGuide.

Current Objective (Global Variable Declaration)

  1. Modulate the duty cycle (onTime) of the LEDs using the knob voltage.
  2. Declare the global variables controlling the knob and pulse width modulation (PWM).

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 (Declaration)

  1. Declare the global constant byte variable knobPin and initialize to the correct value using the statement .
  2. Declare the global constant int variable maxKnobValue and initialize to the correct value using the statement .
  3. Declare the global float variable knobValue and initialize to 0 using the statement .
  4. Declare the global constant int variable pwmPeriod and initialize to 1000 using the statement .
Next Page