Take the 2-minute tour ×
LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. It's 100% free, no registration required.

I've got an RGB sensor (this one with the three LED thingies) and wonder how to access it using NXC.

I know I can SetSensorColorFull(IN_1); and then access it using ReadSensorColorEx or, for simplicity, ReadSensorColorRaw, but I'm a bit stumped wrt. the return values.

I know normal 24-bit (3x8bit) RGB colour codes. I know normal NXC return values (0/1, 0‥100, 0‥255). But I don't know how the values here work.

I've toyed around with i = ReadSensorColorRaw(IN_1, r); where unsigned int r[4];, and got values: i was always 1 (even if the cable was unplugged), and the r[INPUT_RED] aka r[0] values were somewhat usable, and about 0‥60 were black in general, and I got up to 1023 (when holding the sensor towards light), but if I hold the RGB sensor towards anything yellow, green or blue, the values are somewhat off. Also, I found no docs whatsoever as to what r[INPUT_BLANK] is supposed to be.

When unplugging the sensor, I got r = { x, 0, x, 0 } (where x was roughly 120) in my test program just using NumOut to debug the sensors, so I assume that the sensor return values are biased somewhat?

Would using ReadSensorColorEx give somewhat better usable values, or anything else I can use? Do I need to calibrate them first, and if yes, how? To clarify, I don't want the functions that just give back “it's red”, “it's green”, etc. but I want somewhat usable R/G/B colour tuples (and would take Intensity as bonus, although I'm using light sensors for them normally, or SetSensorColorRed if must be).

I'm using NXT Firmware 1.29, and exclusively Open Source tools. If there's anything else needed, information wise, just comment.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.