How to stop a timer into a function from a different function o r global variable?
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
Hi guys. I am trying to make a color button text change every 0.5 secconds. I am working with a guide, so, I use this code:
% --- Executes on button press in CONECTAR.
function CONECTAR_Callback(hObject, eventdata, handles)
% hObject    handle to CONECTAR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%     b=instrhwinfo('bluetooth')
%     b.RemoteNames
%     instrhwinfo('Bluetooth','SB05') %% nombre del dispositivo encontrado en el paso anterior
timer_blink_botones1(hObject, handles);
global bt vel_ang_envio 
%bt = Bluetooth('sb05', 1)
bt = Bluetooth('HC05V4', 1)
bt.BytesAvailableFcnMode = 'terminator';
bt.BytesAvailableFcn = @instrcallback;
bt.OutputEmptyFcn = @instrcallback;
fopen (bt);
%set(handles.CONECTAR,'ForegroundColor',[0,1,0]);
set(handles.DESCONECTAR,'ForegroundColor',[1,0,0]);
set(handles.ENVIAR,'ForegroundColor',[0,0,0]);
stop(handles.t);
and at the end of many button callbacks, the function that activate the timer
function timer_blink_botones1(hObject, eventdata, handles, varargin)
 handles.t = timer(...
     'Name','timer1',...
     'BusyMode', 'queue', 'ExecutionMode',...
     'fixedRate', 'Period', 1);
 set(handles.t, 'TimerFcn', {@blink, hObject});
 start(handles.t);
 %guidata(hObject, handles);
function blink(hObject, eventdata, parent_GUI)
 handles = guidata(parent_GUI);
    set(handles.CONECTAR,'ForegroundColor',[1,1,1]);
    pause(0.5)
    set(handles.CONECTAR,'ForegroundColor',[0,0,0]);
But, I dont know how can I stop the timer, because it still blinking the button color, but I only need while connecting to the bluetooth device. 
Stop(handles.t) isn't woking
댓글 수: 3
  Walter Roberson
      
      
 2019년 4월 19일
				You would expect that if CONECTAR_Callback were to be called before timer_blink_botones1 has created the timer and stored it in the master handles structure.
You could also consider giving the timer a Tag property, and then in CONECTAR_Callback using timerfind() with that Tag, in order to locate the timer
답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
