Main Content

getFreeResourceSlot

Get first free slot of resource

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

Description

slot = getFreeResourceSlot(arduinoObj, resourceName) returns the first available slot or index in a continuous array allocated for the given resource. The slot count starts from 1.

example

Examples

collapse all

Get the free resource slot allocated to a servo object on an Arduino® Uno. This function runs only in the Create and Configure MATLAB Add-On Class of a custom Arduino add-on library.

Create a servo object.

a = arduino();
s1 = servo(a,'D7');

Get free resource slot on the servo object. In this example, the add-on object of the Arduino object is defined as obj in the Constructor. The resource name for a servo object is 'Servo'.

arduinoObj = obj.Parent;
slot1 = getFreeResourceSlot(arduinoObj,'Servo')
slot1 = 
	1

Create a second servo object to see the free resource slot.

s2 = servo(a,'D5');
slot2 = getFreeResourceSlot(arduinoObj,'Servo')
slot2 = 
	2

Clear the first servo object and create a third servo object to see if the first slot is cleared. Make sure to release hardware resources in your Destructor.

clear('s1')
s3 = servo(a,'D4');
slot3 = getFreeResourceSlot(arduinoObj,'Servo')
slot3 = 
	1

Since the slot number is 1 instead of 3, the first slot has been cleared.

Input Arguments

collapse all

Arduino object, specified as an object that is an internal variable called from within classes that derive from matlabshared.addon.LibraryBase.

Name of resource, specified as a character vector.

Output Arguments

collapse all

Slot or index number of the next free resource, returned as a double.

Version History

Introduced in R2015b