Light Sculpture Architecture: Adding the Fade

Home

Current Objective: Create the Light Sculpture 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.

Creating the Fade

  1. Create a new sketch titled "Your_Initials_LightSculpture"
  2. Copy & Paste your Night Light Mode code into the new sketch.
  3. Save it as Your_Initials_LightSculpture
  4. Update your code with the following:

/* Light Sculpture Architecture - Written by Kyle Stewart - Updated 40217*/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                    //
//                                           Function Declarations (Verbs)                                            //
//                                                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Mode Selection
void updateMode();
void updateOffSwitch();
void runLightShow();
void runNightLight();

// Knob Functions
void pwmUsingKnob();
int getOnTimeUsingKnob();
void updateKnobValue();
float gammaCorrect(float ratio);

// Display Functions
void ebbAndFlow(int fadeTime);
void blinkInPairs(int fadeTime);

// Fading Functions
void fadeUp(const byte pin, int duration);
void fadeDown(const byte pin, int duration);
void fadeUpArray(const byte arrayName[], const byte arrayLength, int duration);
void fadeDownArray(const byte arrayName[], const byte arrayLength, int duration);
int getOnTimeUsingFraction(float fractionOn);
void updateStepSize(int duration);

// Helper Functions
void turnOnArray(const byte arrayName[], const byte arrayLength);
void turnOffArray(const byte arrayName[], const byte arrayLength);
void turnOnAll();
void turnOffAll();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                    //
//                                       Global LED Array Declarations (Lists)                                        //
//                                                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Stewart's note: you can change or delete these samples but they are referenced in the instructions

const byte sampleAcrossArray[] = {11, 10, 9, 8, 7, 3, 2, 4, 5, 6, 12, 13, 14, 15};

const byte sampleLeftArray[] =  {11, 10, 9, 8, 7, 3, 2 };
const byte sampleRightArray[] = {15, 14, 13, 12, 6, 5, 4};

Global Variables (Nouns)

In Global Variables (Nouns) under the declaration of pwmPeriod:

  1. Declare a const int named msPerStep and initialize it as 10 with the statement
  2. Declare a float named fadingStepSize and initialize it as the ratio of msPerStep to pwmPeriod with the statement

Add a new Section Header above Helper Functions for Fading Functions In here:

  1. Open the definition of fadeUp with the statement (Hint: Recall to the section Function Declarations for the parameters for fadeUp).
    1. Begin this definition with a for loop that declares a float fractionOn that starts at 0; goes up to 1 (use <); and increments using fadingStepSize (hint: use the += symbol) with the statement
      1. Call the function updateMode with the statement
      2. If the mode does not equal lightShowMode (hint: use != symbol, which means does not equal to), return with the statement
      3. Declare a const int named onTime and initialize it as the value of getOnTimeUsingFraction with fractionOn as the parameter with the statement
      4. Calculate offTime and blink pin.
      5. Call updateStepSize with an argument of duration with the statement
    2. End the definition (after the for loop) by turning on pin with the statement
  2. Define fadeDown, fadeUpArray, and fadeDownArray with this function as a reference.
Next Page