Quiz 8: Mixing RGB Colors

Home

Important Reminders

  • Remember to follow each step and create the code as you go!!
  • Refer frequently to the dpeaArduinoStyleGuide.

Setup

  1. Watch this video on Pulse Width Modulation (PWM), stopping at 0:59 .  Note that the electronics will be handled by our Arduino and LED Shield.
  2. Create a new folder in your Arduino folder named KineticSculpture.
  3. Create a new sketch and save it in the KineticSculpture folder as YourInitials_rgbTesting.ino
  4. Copy and paste the starter sketch given here:

    
    /* KS_RGB_Testing - Written by Kyle Stewart and YOUR_NAME - Updated DATE */
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                            Function Declarations (Verbs)                                           //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    // Transitioning Functions
    void setColors();
    
    // Gamma Correction Functions
    void calculateGammaCorrection(byte rgbArray[]);
    byte readGammaTable(byte input);
    
    // Next Transition Functions
    void checkIfDataIsIncoming();
    void parseStringForNextColor();
    void echoInput();
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                        Global Variable Declarations (Nouns)                                        //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                                   Main Functions                                                   //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                                                                                    //
    //                                              Transitioning Functions                                               //
    //                                                                                                                    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
  5. Open, read, and refer to the dpeaArduinoStyleGuide. Your architecture should follow the formatting and thought process.

Current Objective: Control the LED strip using the red, green, and blue channels.

Requirements

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

Turning on the LED Strip

  1. Congratulations! You've graduated to the Arduino Mega!
  2. Set the Board Type to Arduino/Genuino Mega or Mega 2560 and the Port to the one that says "(Arduino/Genuino Mega)". These are found in the Tools menu
  3. Read this resource on enumeration.
  4. Under the Global Variable Declarations, enumerate the colors red, green, and blue with the statement colors {red, green, blue}; (hint: the answer is the keyword for enumeration).
  5. Examine the following Kinetic Sculpture Printed Circuit Board (PCB) schematic to determine the pins for the red, green, and blue channels:
  6. Declare three global constant byte variables - redPin, greenPin, and bluePin - and assign them values based on the schematic.  The redPin declaration statement is Refer back to the Variables quiz if you need a refresher.
  7. Declare a global constant byte array named rgbPins with the statement = {redPin, greenPin, bluePin};
  8. Declare a global byte array rgbValue and initialize each of its elements to 127.
  9. In the definition of setup, call a function named setColors using the statement (hint: it has no parameters).
  10. In the section named Transitioning Functions, define the function setColors with the statement (hint: it is a void function).
  11. Create a for loop in setColors that declares a byte variable color and increments (color++) it from red to blue using the statement (see the dpeaArduinoStyleGuide for formatting).

  12. Inside of this loop, write each rgbPins[color] with its corresponding rgbValue[color] by calling a built-in Arduino function. Then set the RGB colors by calling the function named . The syntax for this function is similar to digitalWrite(pin, value), where value is between 0 and 255 (one byte).
  13. Read this resource as a reminder of how PWM works.
  14. Upload your code and observe the result.  Let there be light!
  15. Experiment with other combinations of rgbValues Try at least three other combinations to see which you prefer.

Did you create all the code for this page?

Before you click the next button, check you followed EACH instruction!!



Back Next Page