Add Pin Number Property
In this procedure, you modify the System object™ developed in Create a Digital Write Block to include a pin number property that can be set from the block dialog box.
- In the MATLAB® Editor, open the System object class file, - DigitalWrite.m.
- Find the - Nontunableproperties section and add a new property,- pinNumber. Set the value equal to 9.- properties (Nontunable) % Pin Number pinNumber = 9; end - When a property attribute is set to - Nontunable, then it cannot be modified while the model runs. The value assigned to the property is the default value when the block is added to model.
- Update the - setupImplmethod to use the- pinNumberproperty.- methods (Access=protected) function setupImpl(obj) %#ok<MANU> if isempty(coder.target) % Place simulation setup code here else % Call C-function implementing device initialization coder.cinlcude('digitalio_arduino.h'); coder.ceval('digitalIOSetup', obj.pinNumber, 1); end end ... end 
- Update the - stepImplmethod to use the- pinNumberproperty.- methods(Access=protected) ... function stepImpl(obj,u) %#ok<INUSD> if isempty(coder.target) % Place simulation setup code here else % Call C-function implementing device output coder.ceval('writeDigitalPin', obj.pinNumber, u); end end ... end 
- Open the block mask dialog box to verify the addition of the new - pinNumberfield. 
In the next section, you will Add Push Button to View Pin Map to you System object mask.
See Also
Add Description for Users | Add Push Button to View Pin Map | Mapping System Object Code to MATLAB System Block Dialog Box