Display continuous alert in GUI from serial data
Show older comments
Hello guys. I need help to continuously display alert in edit box based on digital serial data recieved, 0 or 1. For now, i only get to read from serial port once so the alerts wont change based on the serial data.
Can anyone show me the coding to add below to continuously display alert based on serial data i recieve from arduino? How should i use loop in this?
Thankyou in advance :)
% --- Executes just before level_simulation is made visible.
function level_simulation_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to level_simulation (see VARARGIN)
% Choose default command line output for level_simulation
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
delete(instrfind({'PORT'},{'COM3'}));
clear a;
clc;
global a;
a = arduino('com3','uno');
x = 0;
global a;
reading = readDigitalPin(a,'D3');
set(handles.edit1,'String',num2str(reading)); % edit1 is the tag of edit box used to display the temperature
if reading == 1
set(handles.edit2,'String','FIRST ALERT'); % edit2 is the tag of edit box used to display the alert
set(handles.edit3,'String','');
elseif reading == 0
set(handles.edit3,'String','SECOND ALERT');
set(handles.edit2,'String','');
else
set(handles.edit2,'String','');
set(handles.edit3,'String','');
end
4 Comments
Walter Roberson
on 13 Nov 2019
global a;
while true
reading = readDigitalPin(a,'D3');
set(handles.edit1,'String',num2str(reading)); % edit1 is the tag of edit box used to display the temperature
if reading == 1
set(handles.edit2,'String','FIRST ALERT'); % edit2 is the tag of edit box used to display the alert
set(handles.edit3,'String','');
elseif reading == 0
set(handles.edit3,'String','SECOND ALERT');
set(handles.edit2,'String','');
else
set(handles.edit2,'String','');
set(handles.edit3,'String','');
end
pause(0.1); %or as appropriate
end
Iemad Sofi
on 13 Nov 2019
Iemad Sofi
on 13 Nov 2019
Walter Roberson
on 13 Nov 2019
Don't put the loop in the open fcn callback.
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!