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. Learn more from the example page.

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.

“There are permissions to be granted by Android M users before they can use the Color shield please make sure to grant the permissions or else it may affect the application’s performance.”

Note :

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.

Helper Classes:

Color class:

Helps returning back details of colors:

1- Red /Green /Blue components.

2- Has “!=” &  “==” operators to check inequality and equality between colors easily.

Return back last color grabbed. “default: Normal mode”

Note: for Full mode give the function which block would you like to grab the color from.

 

Literals: in 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.*/

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

RETURNS

Last color scanned.

PARAMETERS

Default: Normal mode operation (COLOR_CENTER_MIDDLE) .

Custom: Full mode operation (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)

USAGE:

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

Checks if a new Color is received.

SYNTAX

ColorDetector.isNewColorReceived( );

RETURNS

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

PARAMETERS

None.

USAGE

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

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

Literals: both for normal and 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

Literals mentioned above that idicates which set of colors would you like to get.

USAGE

ColorDetector.isNewColorReceived(_3_BIT_RGB_PALETTE);

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();

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

Note: this function is related also by setPatchSize(byte)

SYNTAX

ColorDetector.enableNormalOperation( );

RETURNS

None.

PARAMETERS

None.

USAGE

ColorDetector.enableNormalOperation();

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 calculation mode literals.

USAGE

ColorDetector.setCalculationMode(MOST_DOMINANT_COLOR);

Set the patch “Block” to a certain size to grab color from even wide or small preview.(default LARGE_SIZE )

Works for both normal and full modes.

Literals:

SMALL_SIZE

MEDIUM_SIZE

LARGE_SIZE

SYNTAX

ColorDetector.setPatchSize(size);

RETURNS

None.

PARAMETERS

Takes patch size literals.

USAGE

ColorDetector.setPatchSize(LARGE_SIZE);

Checks if the color shield works in the full mode.

SYNTAX

ColorDetector.isFullOperation( );

RETURNS

A Yes “1” or No “0” for full mode operation.

PARAMETERS

None.

USAGE

ColorDetector.isFullOperation();

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();

Converts RGB grabbed components to HSB (Hue/Saturation/Brightness) values and returned in unsigned long value(4byte value).

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

An unsigned long value holds the hue,saturation & brightness.

PARAMETERS

RGB value to be converted to HSB.

USAGE

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

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();
}

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.setOnNewColorReceived(&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();
}

Returns back the Red color component grabbed by the sensor.

SYNTAX

Color myColor;

myColor.getRed();

RETURNS

A byte represents the red component in the color grabbed.

PARAMETERS

None.

USAGE

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

Returns back the Green color component grabbed by the sensor.

SYNTAX

Color myColor;

myColor.getGreen();

RETURNS

A byte represents the green component in the color grabbed.

PARAMETERS

None.

USAGE

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

Returns back the Blue color component grabbed by the sensor.

 SYNTAX

Color myColor;

myColor.getBlue();

RETURNS

A byte represents the blue component in the color grabbed.

PARAMETERS

None.

 USAGE

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