Adafruit tcs34725 colour sensor remapping to 255 values???

Hi guys and ladies,
Im working on a project using the Adafruit tcs34725 colour sensor and a zumo robot but the example code for the sensor far exceeds my basic understanding.

Here is the example code for the colour sensor.

[quote]
#include <[color=#CC6600]Wire[/color].h>
#include [color=#006699]"Adafruit_TCS34725.h"[/color]

[color=#7E7E7E]// Pick analog outputs, for the UNO these three work well[/color]
[color=#7E7E7E]// use ~560  ohm resistor between Red & Blue, ~1K for green (its brighter)[/color]
#define redpin 3
#define greenpin 5
#define bluepin 6
[color=#7E7E7E]// for a common anode LED, connect the common pin to +5V[/color]
[color=#7E7E7E]// for common cathode, connect the common to ground[/color]

[color=#7E7E7E]// set to false if using a common cathode LED[/color]
#define commonAnode [color=#CC6600]true[/color]

[color=#7E7E7E]// our RGB -> eye-recognized gamma color[/color]
[color=#CC6600]byte[/color] gammatable[256];


Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color]([color=#006699]"Color View Test!"[/color]);

  [color=#CC6600]if[/color] (tcs.[color=#CC6600]begin[/color]()) {
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color]([color=#006699]"Found sensor"[/color]);
  } [color=#CC6600]else[/color] {
    [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color]([color=#006699]"No TCS34725 found ... check your connections"[/color]);
    [color=#CC6600]while[/color] (1); [color=#7E7E7E]// halt![/color]
  }
  
  [color=#7E7E7E]// use these three pins to drive an LED[/color]
  [color=#CC6600]pinMode[/color](redpin, [color=#006699]OUTPUT[/color]);
  [color=#CC6600]pinMode[/color](greenpin, [color=#006699]OUTPUT[/color]);
  [color=#CC6600]pinMode[/color](bluepin, [color=#006699]OUTPUT[/color]);
  
  [color=#7E7E7E]// thanks PhilB for this gamma table![/color]
  [color=#7E7E7E]// it helps convert RGB colors to what humans see[/color]
  [color=#CC6600]for[/color] ([color=#CC6600]int[/color] i=0; i<256; i++) {
    [color=#CC6600]float[/color] x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;
      
    [color=#CC6600]if[/color] (commonAnode) {
      gammatable[i] = 255 - x;
    } [color=#CC6600]else[/color] {
      gammatable[i] = x;      
    }
    [color=#7E7E7E]//Serial.println(gammatable[i]);[/color]
  }
}


[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {
  uint16_t [color=#CC6600]clear[/color], red, green, blue;

  tcs.setInterrupt([color=#CC6600]false[/color]);      [color=#7E7E7E]// turn on LED[/color]

  [color=#CC6600]delay[/color](60);  [color=#7E7E7E]// takes 50ms to read [/color]
  
  tcs.getRawData(&red, &green, &blue, &[color=#CC6600]clear[/color]);

  tcs.setInterrupt([color=#CC6600]true[/color]);  [color=#7E7E7E]// turn off LED[/color]
  
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"C:\t"[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#CC6600]clear[/color]);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"\tR:\t"[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](red);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"\tG:\t"[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](green);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"\tB:\t"[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](blue);

  [color=#7E7E7E]// Figure out some basic hex code for visualization[/color]
  uint32_t sum = [color=#CC6600]clear[/color];
  [color=#CC6600]float[/color] r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"\t"[/color]);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](([color=#CC6600]int[/color])r, [color=#006699]HEX[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](([color=#CC6600]int[/color])g, [color=#006699]HEX[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](([color=#CC6600]int[/color])b, [color=#006699]HEX[/color]);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color]();

  [color=#7E7E7E]//Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" ");  Serial.println((int)b );[/color]

  [color=#CC6600]analogWrite[/color](redpin, gammatable[([color=#CC6600]int[/color])r]);
  [color=#CC6600]analogWrite[/color](greenpin, gammatable[([color=#CC6600]int[/color])g]);
  [color=#CC6600]analogWrite[/color](bluepin, gammatable[([color=#CC6600]int[/color])b]);
}

[/quote]/code]

I would like it to map the r, g, b sensor values each from 0, 255
and code the equivalent; (i know this isn't actual code but just for example)

if sensor reading r = 255 && b =< 100 && b =< 100
then Serial.print("red") and buzzer.playNote(NOTE_A(5), 200, 15);

buzzer.playNote(NOTE_A(5), 200, 15); isn't part of the provided code but i will include the library for this when i test your suggestions.

if someone would be so kind to help me with this then i could continue with the rest of the colour/note coding into the zumo code i have been working on. I understand its hard to help without having a sensor to test but hopefully it isn't a major problem.
Thank you for your time.

sorry this accidentally got include in the code instead of the post.

I would like it to map the r, g, b sensor values each from 0, 255
and code the equivalent; (i know this isn't actual code but just for example)

if sensor reading r = 255 && b =< 100 && b =< 100
then Serial.print("red") and buzzer.playNote(NOTE_A(5), 200, 15);

buzzer.playNote(NOTE_A(5), 200, 15); isn't part of the provided code but i will include the library for this when i test your suggestions.

if someone would be so kind to help me with this then i could continue with the rest of the colour/note coding into the zumo code i have been working on. I understand its hard to help without having a sensor to test but hopefully it isn't a major problem.
Thank you for your time.

You are not necessarily going to get r=255 just because it is red.

I suggest you do some experiements to see what answers you get from the device, and understand that,
BEFORE you write heaps of code which is not going to work.

Hi

thanks for the reply,
i understand that the sensor seeing red will not necessarily return 255 if mapped i just am trying to lower the values so its easier to deal with if that makes sense. The readings go from hundreds to over 20,000+ without maxing out.
I have been testing the sensor and playing around with it but i don't know how to get any of the readings from the sensor into an if statement. Basically i am asking which part of the example should i include in an if statement to get the r, g, and b sensor readings???
As a terrible example;

if (the variable I'm looking for but can't see in the example for R > 75780 && the variable for G which i also can't see < 138674 && the variable for B which i also can't see < 647874)
{
// do something here
}

I apologise for my lack of understanding but I am trying.
Hopefully I have better explained myself.
Thanks

i understand that the sensor seeing red will not necessarily return 255 if mapped i just am trying to lower the values so its easier to deal with if that makes sense.

You answered your own question. Use the map function.