Hi, I made a GUI where I put a timer with the timer function linked to Arduino. So to get data from Arduino I need to define his port and type everytime and this wastes a huge amount of time. How can I avoid defining the arduino properties all the time?
I tried to put a global a, arduino object, but it doesn't seem to work.
This is the GUI Function callback:
function CmdStart_Callback(hObject, eventdata, handles)global txtTime Timer1 set(handles.CmdStart, 'Enable', 'Off'); %Disabilita il bottone per lo start dopo che questo รจ stato premuto.
disp('Start Timer'); Timer1= timer('name','Period'); Timer1.ExecutionMode = 'FixedSpacing'; Timer1.Period = txtTime; Timer1.TimerFcn = @SoilHumidityforGUI; Timer1.ErrorFcn = @ErrorFcn; start (Timer1); end
And this is the function called by the timer.
function SoilHumidityforGUI (~,~) a= arduino ('com3', 'mega2560'); H= (readVoltage (a, 'A0')); end
Thanks
Best Answer