Quiz 8: Mixing RGB Colors

Home

Current Objective: Getting Values from the Serial Monitor

Remember to follow each step and create the code as you go!!


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.

Getting Values from the Serial Monitor

1. Declare the global boolean variable dataIsIncoming and initialize it to false using the statement (use the declaration bool).  Booleans can only be true or false, and we use them to monitor the state of the system.

2. In setup, open Serial communications between the Arduino and your PC using the statement .


3. In loop, call a function named checkIfDataIsIncoming using the statement .


4. Add an if statement whose condition is the boolean variable using the statement .


5. Call a function parseStringForNextColor using the statement .  To parse is to read, analyze, and interpret.  A string is an array of characters (letters, numbers, symbols).


6. Copy the calls to calculateGammaCorrection and setColor from setup into this if statement.


7. Add a Communication Functions header prior to Gamma Correction.


8. Open the function definition of checkIfDataIsIncoming using the statement .


9. Search the Internet for Arduino Serial and read the names of the functions Arduino provides with the library.


10. Check if there is Serial input available to the Arduino from the computer using the statement .


11.
If so, assign the dataIsIncoming to be true. Else, assign it to be false.


12. Open the function definition of parseStringForNextColor using the statement .


13. Add a color for loop.


14. Declare a byte variable parsedValue and assign it to be the next parsed integer using  the statement .


15. Assign
the color element of rgbValue to be the parsedValue using the statement .


16. After the for loop, echo the parsed string back to the PC from the Arduino by using the following code:

    String rgbString = rgbValue[0] + String(", ") + rgbValue[1] + String(", ") + rgbValue[2];
    Serial.println(rgbString);

17. Upload your code and open the Serial Monitor (CTRL+SHIFT+M)


18.Test your code by sending triplets of colors in the format r.g.b to set the LED colors.


19. An example line is 0.0.255 to turn on pure blue.


20. You can separate values with spaces, periods, commas, or any other non-numeric character.

21. You should see your input echoed in the Serial Monitor.

Check Your Understanding

1. The definition of the main functions setup and loop only have two things: (two words) to perform tasks and if statements to check the Boolean state variables.


2. This program sets RGB colors by them from the user-provided Serial Monitor RGB triplets.


3. Scaling the RGB values to linearize them for the human eye is referred to as (two words).

Congratulations! At this point, you should have all your code ALREADY WRITTEN. If you don't, go back and carefully follow the instructions of each question!!



Back