Home‎ > ‎CS 11M‎ > ‎

Colorimeter -- Part 2

Introduction

In this project you will complete your colorimeter by having it perform calibration and color reading operations. 

Reading a Color

Reading a color works like like this:
  1. Turn off the RGB LED and sample the photosensor.
    1. Save the measurement as the "black" value
  2. Turn on the red LED full brightness and sample the photosensor. 
    1. Subtract the black value from the reading. 
    2. Store the reading as the red value
  3. Repeat step 2 for both the green and the blue LEDs
  4. Save your sketch as colorimeter-part2.ino
After the procedure you should have R, G and B values that represent the color of reflected light on an object near the LED and photosensor. Return that as a Color object. The work should be performed by a function called getReflectedColor with the signature:

Color getReflectedColor()

Specifications

Your colorimeter should take a reading when you press the left button (the button on pin 13) and immediately display the dominant color. Here's an example of the output: 


Press the LEFT button to measure
The color was: r: 12 g: 143 b: 233
The dominant color is: blue 

To summarize:
  • Take a reading when the LEFT button (pin 13) is pushed. 
  • Print the reading as shown above. 

Extra Credit

You are already calibrating the black level. You can improve the accuracy of your colorimeter by calibrating it against a white object. A white object helps calibrate the colorimeter by eliminating errors due to the sensitivity of the photosensor. The photosensor happens to see red much better than it sees blue. You will use the white level to normalize the reading using the following formula:

normalized_reading = (reading - black_level) / white_level  

Notice that the domain of normalized_reading should be [0, 1]. You will have to make sure that you adjust accordingly (and don't forget to use floats!). Use the getReflectedColor() function from the previous part to get your white level and add a new, overloaded, function:

Color getReflectedColor(const Color &white_level)

Use your overloaded function to read the corrected color. 

Specifications

  1. Your program should operate the same as the previous part with the following additions
  2. When the RIGHT (pin 12) button is pushed take a calibration reading
  3. Correct all subsequent readings using the calibrated reading.
  4. Save your sketch as colorimeter-part2xc.ino

Turn In

Turn in your sketches on Canvas.
Comments