Color Detector Shield acts as Arduino Shield via 1Sheeld

Buy 1Sheeld

Color detector shield allows you to detect colors with your smartphone camera, and trigger the Arduino to take actions based on the colors detected.

This shield is one of the sensor shields. Sensor shields allows you to tap into your smartphone’s sensors and use in prototyping with Arduino, you can get information from the surrounding environment and use it to trigger a certain action. Learn more from the sensor shields tutorial.

Color sensor shield allows you detect colors with your smartphone camera, and trigger the Arduino to take actions based on the colors detected.

Adding #define CUSTOM_SETTINGS along with #define INCLUDE_COLOR_DETECTOR_SHIELD is a key that will let you unlock the Color Detector shield only amongst all shields and prevent 1Sheeld library from eating your memory specially for UNO board.

Notes

– For Android M(6) or greater, there are permissions to be granted before using the Data Logger shield, please make sure to grant the permissions or else it may affect the application’s performance.
– There are two functional types in color shield Full mode and Normal mode.
– Full mode:Works as a 9 grid matrix from the camera preview.
– Normal mode: Grabs colors from center of the camera preview.

Color class (Helper class)

Helps returning back details of colors:
– Red /Green /Blue components.
– Has “!=” &  “==” operators to check inequality and equality between colors easily.

 

Color getLastColor(byte)

Return back last color grabbed.(default: Normal mode)

Literals (Full Mode)

COLOR_UPPER_LEFT
COLOR_UPPER_MIDDLE
COLOR_UPPER_RIGHT
COLOR_CENTER_LEFT
COLOR_CENTER_MIDDLE
COLOR_CENTER_RIGHT
COLOR_LOWER_LEFT
COLOR_LOWER_MIDDLE
COLOR_LOWER_RIGHT

SYNTAX
ColorDetector.getLastColor( ); /* for normal mode.
Or
ColorDetector.getLastColor(COLOR_UPPER_MIDDLE); /* for full  mode.*/

RETURNS
Returns an object Color holding the color components values.

PARAMETERS
Takes a byte holding the block patch from where it can return the colors sensed.(Default normal mode, the bock patch is the center)

USAGE
Color myColor = ColorDetector.getLastColor();
or 
ColorDetector.enableFullOperation();
Color myColor =  ColorDetector.getLastColor(COLOR_UPPER_LEFT);

 

bool isNewColorReceived(void)

Checks if a new Color is received.

SYNTAX
ColorDetector.isNewColorReceived();

RETURNS
Returns a Yes “1” or No “0” if a new color received.

PARAMETERS
None.

USAGE
bool newColorReceived = ColorDetector.isNewColorReceived( );
if(newColorReceived)
{/* do my code. */};

 

void setPalette(byte)

Sets color palette which sets a finite number of colors for the management of digital images.

Literals (Normal&Full Mode)

_1_BIT_GRAYSCALE_PALETTE
_2_BIT_GRAYSCALE_PALETTE
_4_BIT_GRAYSCALE_PALETTE
_8_BIT_GRAYSCALE_PALETTE
_3_BIT_RGB_PALETTE
_6_BIT_RGB_PALETTE
_9_BIT_RGB_PALETTE
_12_BIT_RGB_PALETTE
_15_BIT_RGB_PALETTE
_18_BIT_RGB_PALETTE
_24_BIT_RGB_PALETTE

SYNTAX
ColorDetector.setPalette(paletteSetNumbers);

RETURNS
None.

PARAMETERS
Takes a byte holding one of the literals mentioned above.

USAGE
ColorDetector.setPalette(_3_BIT_RGB_PALETTE);

 

void enableFullOperation(void)

Enable full operation mode which customize the preiview to a 9 grid matrix.

Note:
This function is related also to setPatchSize(byte).

SYNTAX
ColorDetector.enableFullOperation();

RETURNS
None.

PARAMETERS
None.

USAGE
ColorDetector.enableFullOperation();

 

void enableNormalOperation(void)

Enable normal  operation mode.(default unless changed by enabling full mode).

Note:
This function is related also to setPatchSize(byte).

SYNTAX
ColorDetector.enableNormalOperation();

RETURNS
None.

PARAMETERS
None.

USAGE
ColorDetector.enableNormalOperation();

 

void setCalculationMode(byte)

– Sets how to grab the colors even the average between the RGB components or get the most dominant component.
– Works for both normal and full mode.

Literals

MOST_DOMINANT_COLOR
AVERAGE_COLOR

SYNTAX
ColorDetector.setCalculationMode(calculationMode);

RETURNS
None.

PARAMETERS
Takes a byte holding one of the Literals above.

USAGE
ColorDetector.setCalculationMode(MOST_DOMINANT_COLOR);

 

void setPatchSize(byte)

Works for both normal and full modes.

Literals

SMALL_SIZE
MEDIUM_SIZE
LARGE_SIZE

SYNTAX
ColorDetector.setPatchSize(size);

RETURNS
None.

PARAMETERS
Takes a byte holding one of the Literals above.

USAGE
ColorDetector.setPatchSize(LARGE_SIZE);

 

void isFullOperation(void)

Checks if the color shield works in the full mode.

SYNTAX
ColorDetector.isFullOperation();

RETURNS
Returns a Yes “1” or No “0” for full mode operation..

PARAMETERS
None.

USAGE
ColorDetector.isFullOperation();

 

void finishedReading(void)

Used in full mode operation once finished dealing with the colors grabbed by the 9 patches “blocks”. Write the syntax after you had finished reading the 9 colors to prevent new color values interference with the old color values.

SYNTAX
ColorDetector.finishedReading();

RETURNS
None.

PARAMETERS
None.

USAGE
ColorDetector.finishedReading();

 

unsigned long covertRgbToHsb(unsigned long)

– Used in full mode operation once finished dealing with the colors grabbed by the 9 patches “blocks”. Write the syntax after you had finished reading the 9 colors to prevent new color values interference with the old color values.
– Needs some bit manipulation operations to return each specific value for Hue, Saturation & Brightness.
– 1st&2nd from right bytes “Hue”.
– 3rd byte “Saturation”.
– 4th byte “Brightness”.

SYNTAX
ColorDetector.covertRgbToHsb(rgbValue);

RETURNS
Returns an unsigned long holding the hue,saturation&brightness bytes.

PARAMETERS
Takes an unsigned long holding the RGB value to be converted to HSB.

USAGE
unsigned long hsbValue =  ColorDetector.covertRgbToHsb(0xffffff);

 

void setOnNewColor(void (userFunction)(Color))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new color received in Normal operation mode.

SYNTAX
ColorDetector.setOnNewColor(&userFunctionName);

RETURNS
None.

PARAMETERS
&userFunctionName: takes the physical address of the userFunction in the memory and jump to it once called to execute it’s functionality.

USAGE
/* Subscribe to the new color received event. */
ColorDetector.setOnNewColor(&colorFunction);
/* colorFunction exists under the loop function. */
/* A function to be called once a new color is received. */
void colorFunction(Color myColor)
{
  byte redComponent = myColor.getRed();
}

 

void setOnNewColor(void (userFunction)(Color,Color,Color,Color,Color,Color,Color,Color,Color))

Sets a certain individual function coded by the user in the sketch to be called and runs its functionality once a new color received in full operation mode.

SYNTAX
ColorDetector.setOnNewColor(&userFunctionName);

RETURNS
None.

PARAMETERS
&userFunctionName: takes the physical address of the userFunction in the memory and jump to it once called to execute it’s functionality.

USAGE
/* Enable full mode operation. */
ColorDetector.enableFullOperation();
/* Subscribe to the new color received event. */
ColorDetector.setOnNewColor(&colorFunction);
/* colorFunction exists under the loop function. */
/* A function to be called once a new color is received. */
void colorFunction(Color myColor1,Color myColor2,Color myColor3,Color myColor4, Color myColor5,Color myColor6,Color myColor7,Color myColor8,Color myColor9)
{
  byte redComponent = myColor1.getRed();
  byte redComponent = myColor2.getRed();
  byte redComponent = myColor3.getRed();
  byte redComponent = myColor4.getRed();
  byte redComponent = myColor5.getRed();
}

 

Color Class Functions:

 

byte getRed(void)

Returns back the Red color component grabbed by the sensor.

SYNTAX
Color myColor;
myColor.getRed();

RETURNS
Returns a byte represents the red component in the color grabbed.

PARAMETERS
None.

USAGE
Color myColor = ColorDetector.getLastColor();
byte redComponent =  myColor.getRed();

 

byte getGreen(void)

Returns back the Green color component grabbed by the sensor.

SYNTAX
Color myColor;
myColor.getGreen();

RETURNS
Returns a byte represents the green component in the color grabbed.

PARAMETERS
None.

USAGE
Color myColor = ColorDetector.getLastColor();
byte redComponent =  myColor.getGreen();

 

byte getBlue(void)

Returns back the Blue color component grabbed by the sensor.

SYNTAX
Color myColor;
myColor.getBlue();

RETURNS
Returns a byte represents the blue component in the color grabbed.

PARAMETERS
None.

USAGE
Color myColor = ColorDetector.getLastColor();
byte redComponent =  myColor.getBlue();