Color Sensor

  1. include "mbed.h"
  2. include "TCS3200.h"

TCS3200 color(PC_9, PB_8, PB_9, PA_5, PA_6); Create a TCS3200 object S0 S1 S2 S3 OUT

DigitalOut whiteleds(PC_8); Output pin to drive white LEDs

int main() { long red, green, blue, clear;

Set the scaling factor to 100% color.SetMode(TCS3200::SCALE_100); other options: SCALE_2 and SCALE_20 - depending on lightning conditions

whiteleds = 1;

while(1){ /* Read the HIGH pulse width in nS for each color. The lower the value, the more of that color is detected */ red = color.ReadRed(); green = color.ReadGreen(); blue = color.ReadBlue(); clear = color.ReadClear();

/* Display pulse values in nano seconds (nS) */ printf("RED: %10d GREEN: %10d BLUE: %10d CLEAR: %10d ", red, green, blue, clear);

/* Determine if the color detected is most likely RED, GREEN, or BLUE */ if((red < green) && (red < blue)) printf("RED\n"); else if((green < red) && (green < blue)) printf("GREEN\n"); else if((blue < red) && (blue < green)) printf("BLUE\n"); else printf("????\n");

wait(0.1); } }


Please log in to post comments.