Thank you for your answer.
I did some research and I managed to improve speed of this command for around 7 times, so it is quite faster.
Go to source code of function arduino() in Matlab (arduino.m)
Find fuction writeDigitalPin:
function writeDigitalPin(obj, pin, value)
% Write digital pin value to Arduino hardware.
%
% Syntax:
% writeDigitalPin(a,pin,value)
%
% Description:
% Writes specified value to the specified pin on the Arduino hardware.
%
% Example:
% a = arduino();
% writeDigitalPin(a,'D13',1);
%
% Input Arguments:
% a - Arduino hardware
% pin - Digital pin number on the Arduino hardware (string)
% value - Digital value (0, 1) or (true, false) to write to the specified pin (double).
%
% See also readDigitalPin, writePWMVoltage, writePWMDutyCycle
try
if (nargin < 3)
obj.localizedError('MATLAB:minrhs');
end
pin = arduinoio.internal.validateInputPin(pin, arduinoio.internal.SubsystemEnum.Digital);
configurePinResource(obj, pin, obj.ResourceOwner, 'DigitalOutput', false);
value = arduinoio.internal.validateDigitalParameter(value);
if pin(1) == 'A'
pin = getPinAlias(obj, pin);
end
writeDigitalPin(obj.Protocol, pin, value);
catch e
throwAsCaller(e);
end
end
all you have to do now is comment this line:
configurePinResource(obj, pin, obj.ResourceOwner, 'DigitalOutput', false);
so it looks like that:
function writeDigitalPin(obj, pin, value)
% Write digital pin value to Arduino hardware.
%
% Syntax:
% writeDigitalPin(a,pin,value)
%
% Description:
% Writes specified value to the specified pin on the Arduino hardware.
%
% Example:
% a = arduino();
% writeDigitalPin(a,'D13',1);
%
% Input Arguments:
% a - Arduino hardware
% pin - Digital pin number on the Arduino hardware (string)
% value - Digital value (0, 1) or (true, false) to write to the specified pin (double).
%
% See also readDigitalPin, writePWMVoltage, writePWMDutyCycle
try
if (nargin < 3)
obj.localizedError('MATLAB:minrhs');
end
pin = arduinoio.internal.validateInputPin(pin, arduinoio.internal.SubsystemEnum.Digital);
% configurePinResource(obj, pin, obj.ResourceOwner, 'DigitalOutput', false);
value = arduinoio.internal.validateDigitalParameter(value);
if pin(1) == 'A'
pin = getPinAlias(obj, pin);
end
writeDigitalPin(obj.Protocol, pin, value);
catch e
throwAsCaller(e);
end
end
Than you have to declare every pin that you want as digital output with this command:
configurePin(a,pin,'DigitalOutput');
With that you can declare only once and when code runs, it won't be slow 