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

6 views (last 30 days)
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)

Matthew Kuo
Matthew Kuo on 21 Apr 2016
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
Deepansh Bhatia
Deepansh Bhatia on 1 Mar 2018
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.
Katie Red
Katie Red on 1 Mar 2018
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

Community Treasure Hunt

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

Start Hunting!