Hauptinhalt

Custom Arduino Library Resources

R2026b

A custom Arduino® library resource can exist only as a limited or single instance. Resources can be pins, properties, or custom Arduino library instances themselves. By specifying and acquiring resources in your custom Arduino library, you protect the resource from being acquired or altered by another custom Arduino library. For example, a pin set by a custom Arduino library to act as an analog input must not be allowed to be changed to a digital output by another custom Arduino library. Two types of resources exist for a custom Arduino 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 of 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 because 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 a custom Arduino library class using a shared communication resource must set the properties of the bus to be the same. Once the first custom Arduino 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

| | |

Topics