Main Content

Add-On Resources

An Arduino® add-on library resource can exist only as a limited or single instance. Resources can be pins, properties, or add-on instances themselves. By specifying and acquiring resources in your add-on library, you protect the resource from being acquired or altered by another add-on. For example, a pin set by add-on library to act as an analog input must not be allowed to be changed to a digital output by another add-on library. Two types of resources exist for an add-on library: Counted and Shared

Counted

A counted resource is limited to certain number of instances due to pin usages or application constraints. The incrementResourceCount and decrementResourceCount enable you to increment and decrement the number or instances of the resource. When a counted resource increments, the next available resource is always taken in order. Similarly, when decremented, the last acquired resource is released.

For example, an LCD shield can be a counted resource since only one LCD shield can exist in MATLAB® at the same time.

Shared

A shared resource is used by multiple objects of the same class. In a shared resource, when any object modifies a property of that resource, the change is applied to all other objects that use the resource. To modify a shared resource, use the getSharedResourceProperty and setSharedResourceProperty functions.

For example, all instances of an add-on library class using a shared communication resource must set the properties of the bus to be the same. Once the first add-on library instance acquires the resource, any later instance must query and set the bus property to the same value as the first instance.

See Also

| | |

Related Topics