How to get RGB values using MATLAB LEGO Mindstorms EV3 color sensor?

I know that readColor() will output the color that is read from the color sensor but I was wondering if there is any way to output the actual RGB values that is read.

Answers (1)

Yes! Go to the folder C:\MATLAB\SupportPackages\R2015a\legomindstormsev3io\toolbox\realtime\targets\ev3io. Yours may be slightly different depending on where you installed it and what version of Matlab you have. Open colorSensor.m and scroll down until you see
methods (Hidden = true)
result = readColorRGB(obj,format)
Delete the line that says (Hidden = true). Now when you call readColorRGB, you will get a struct with the RGB values. For example:
result = readColorRGB(mycolorsensor);
% result(1) is the red value, result(2) is the green value, result(3) is the blue value

2 Comments

Hey! I was looking for this solution, and I went to the colorSensor.m file but I found this:
methods (Static, Hidden = true)
% convert color ID to string
function result = convertColorID(id)
switch id
case 0
result = 'none';
case 1
result = 'black';
case 2
result = 'blue';
case 3
result = 'green';
case 4
result = 'yellow';
case 5
result = 'red';
case 6
result = 'white';
case 7
result = 'brown';
otherwise
result = 'none';
end
end
end %END of static methods
What exactly do I delete in order to get RGB values? Thanks.
It should be line 89 . I found the same thing you found at first . It's there .

Sign in to comment.

Categories

Find more on MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware in Help Center and File Exchange

Asked:

on 12 Mar 2016

Commented:

on 1 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!