1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| function GUI_start()
% init figure control
close all
clc
hObj=figure(); % my big parent handle
uicontrol(gcf,'Style', 'push', 'String', 'PLAY','FontSize',24,'units','normalized','Position',[0.1 0.1 0.5 0.2],'tag','PressStart','CallBack', @code_readArduinoAnalog);
Volt=uicontrol(gcf,'Style', 'edit', 'String', '0','FontSize',10,'units','normalized','Position',[0.1 0.5 .5 .2]);
setappdata(hObj,'Volt',Volt);
% init arduino
a=arduino('COM7','due');
setappdata(hObj,'a',a);
function code_readArduinoAnalog(hObjButtonStart,~,~) %(source,event,handleGlobal)
a=getappdata(hObjButtonStart.Parent,'a');
data=readVoltage(a,'A1');
set(getappdata(hObjButtonStart.Parent,'Volt'),'String',num2str(data));
%% where to put and how to call it ???
function code_readArduinoDigital(hObjButtonPhysical,~,~)
a=getappdata(hObjButtonPhysical.Parent,'a');
while 1==1 % infite loop to read in continuous the digital pin
if readDigitalPin(a,'D13')==0
% the physical button links in pin13 allows to lauch the measure as the pushbutton in GUI
hStart=findobj('tag','pressStart');
feval(get(hStart,'Callback'),hStart,[]);
end
end |
Partager