function result=GetBoxColor (dev,WHITE,GREEN,BLACK,YELLOW,BLUE,RED)

size = 8;
i=0;
while i < size
i=i+1;
ColorData(i) = readRegister(dev, 0X50+i-1,'uint8');

end

% 
% Prirazovani dat pro jednotlive barvy
% 

A=uint16 (ColorData(2));
B=bitsll(A,8);
Redvalue=bitor(B,ColorData(1));

A=uint16 (ColorData(4));
B=bitsll(A,8);
Greenvalue=bitor(B,ColorData(3));

A=uint16 (ColorData(6));
B=bitsll(A,8);
Bluevalue=bitor(B,ColorData(5));

A=uint16 (ColorData(8));
B=bitsll(A,8);
Colorvalue=bitor(B,ColorData(7));

%   format long 
 
% 
% korekce
% 

  uint16 r;
  uint16 g;
  uint16 b;
  r = Redvalue / 20;
  g = Greenvalue / 30;
  b = Bluevalue / 20;
  if(r>255) 
  
    r=255;
    
  end
  if(g>255) 
  
    g=255;
    
  end
  
  if(b>255) 
  
    b=255;
    
  end
  

B=bitsll(r,16);
A=bitsll(g,8);
colorcode =  B + A+ b;
  
    
    r = Redvalue / Colorvalue;
    g = Greenvalue / Colorvalue;
    b = Bluevalue / Colorvalue;
   
%     
%    Porovnani sily kazde barvy 
%     

if(r >= 9 && g <= 4 && b <= 1)
    
      result = RED;
    
    elseif(r > 10 && g <= 4 && b <= 4)
    
      result = RED;
    
        elseif(r < 3 && g <= 4 && b < 3)
    
      result = BLACK;
    
        elseif(r <= 5 && g > 10 && b < 5)
    
      result = GREEN;
    
        elseif((r < 5 && g < 5 && b > 10) || (r <= 3 && g >= 8 && b >= 8))
    
      result = BLUE;
    
        elseif(r >= 5 && g > 6 && b >= 7)
    
      result = BLUE;
    
        elseif(r <= 4 && g >= 10 && b >= 6)
    
      result = BLUE;
    
    elseif(r <= 8 && r >= 6 && g >= 6 && b < 2)
    
      result = YELLOW;
    
%     elseif(r <= 8 && r <= 8 && b < 2)
 
%       result = RED;
    
    elseif(r >= 10 && g <= 7 && b < 2)
    
      result = RED;
    
    elseif(r >= 4 && g >= 9 && b >= 4)
    
      result = WHITE;
    
    else
    
      result = WHITE;
    
  
  
 end
    
disp(result)

end

