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

1 回表示 (過去 30 日間)
Juan Jose Ortiz Torres
Juan Jose Ortiz Torres 2019 年 4 月 19 日
コメント済み: Walter Roberson 2019 年 4 月 19 日
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 Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by