Night Light Mode: Creating the Modes

Home

Current Objective: Create the Light Sculpture Modes

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 Modes

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

/* Light Sculpture Night Light Mode - 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);

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

Global Variables (Nouns)

To enumerate is to list a number of related things. For instance: enum Flavors {strawberry, vanilla, chocolate}; would lead to some tasty Neapolitan.

You can also declare variables based on the enumerated type. For instance: Flavors bestFlavor = chocolate;

Boolean variables can only be true or false. For instance: bool codingIsFun = true;

  1. Enumerate the Modes: offMode, lightShowMode, and nightLightMode with the statement
  2. Declare a Modes variable named mode and initialize it as offMode with the statement
  3. Declare a Boolean variable named switchIsOff and initialize it as true with the statement
  4. Declare a const byte named switchPin and initialize it to pin A4 with the statement
  5. Declare a const int named nightLightRange and initialize it to 255 with the statement
  6. Declare a const int named nightLightMinValue and initialize it to the difference of nightLightRange from maxKnobValue with the statement
Next Page