How to stop a timer into a function from a different function o r global variable?

조회 수: 1 (최근 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
Juan Jose Ortiz Torres
Juan Jose Ortiz Torres 2019년 4월 19일
Ok, I uncommment that, but still not working, the error is:
Reference to non-existent field 't'.
Walter Roberson
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 CenterFile Exchange에서 Platform and License에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by