function T = flash(obj,ftr,col1,col2,N)
% FLASH  allows the highlighting of an UI-Object in a flashing way
% T = flash(h,feature,color1,color2,N)
% Input-Parameters
%    h - handle of the object which should be highlighted
%    feature - object feature, e.g. Color, ForegroundColor, BackgroundColor
%    color1 - first color
%    color2 - second color
%    N - the count of flashs (use "Inf" for endless flashing)
% 
% Output-Parameter
%    T - timer handle (necessary to stop flashing, when N = Inf)
%
% Example 1
%    x = [0:0.01:2*pi];
%    h1 = plot(x,sin(x),'r');
%    flash(h1,'Color',[1 0 0],[1 1 1],11)
%
% Example 2
%    h2 = uicontrol('string','ok')
%    flash(h2,'BackgroundColor',[1 0 0],[.8 .8 .8],10)
%
% Example 3
%    h2 = uicontrol('string','ok')
%    T = flash(h2,'BackgroundColor',[1 0 0],[.8 .8 .8],Inf)
%    to stop the endless flashing use
%    stop(T)

% Author: MCommander@gmx.de
% Version: 1.0

T = timer('TimerFcn',{@flash_fcn,obj,ftr,col1,col2}, ...
          'Period',0.25, ...
          'BusyMode','queue', ...
          'ExecutionMode','fixedDelay', ...
          'TasksToExecute',N, ...
          'ObjectVisibility','off', ...
          'StopFcn',{@flash_stop});
start(T);
%
function flash_stop(T,cnc)
delete(T)
%
function flash_fcn(T,cnc,obj,ftr,col1,col2)
T.TimerFcn = {@flash_fcn,obj,ftr,col2,col1};
set(obj,ftr,col1)
