Home‎ > ‎CS 11M‎ > ‎

Colorimeter -- Part 1


In this project you will implement the first part of a color measuring program. For this part you will create a color class that has appropriate methods and uses good data-hiding style. In the next part you will export your class as a library and implement the color measurement. 

Your Color Class

Your color class should be implemented using proper C++ coding style. That means you should have the definition of the class in a header file. The code below is the definition of your Color class:

class Color { 
  Color(int r, int g, int b);
  void display(); 
  void setRed(int r); 
  void setGreen(int g);
  void setBlue(int b); 
  int getRed();
  int getGreen();
  int getBlue();
  string getDominantColor(); 
  int red;
  int green;
  int blue; 
  static const int redLED = 11; 
  static const int greenLED = 10; 
  static const int blueLED = 9;   

The code above is not a complete Color.h file. You will have to fill in the missing parts!


  • The members of the class should do the following
    • Color() and Color(int, int, int) - Constructors initialize the class as we have done in class exercises. 
    • display() - Place the color onto the 3-color LED pixel. 
    • set/get methods - Set and get the corresponding color component. 
    • getDominantColor() - Return a string that is the color with the highest intensity. It should return one of:
      • "red"
      • "green"
      • "blue"
  • The code for your Color class should be in Color.h and Color.cpp not in the main part of your sketch. 
  • Your sketch should be named colorimeter.ino
  • Your code should read three integers from the serial port and display the corresponding color on the LED. 


You must submit the project as a ZIP file containing all three parts: 
  1. colorimeter.ino
  2. Color.h
  3. Color.cpp
Also submit the class exercises from the previous two weeks. Submit your project on Canvas.