This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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.

  1. In the MATLAB® Editor, open the System object class file, DigitalWrite.m.

  2. Find the Nontunable properties 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.

  3. Update the setupImpl method to use the pinNumber property.

    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
  4. Update the stepImpl method to use the pinNumber property.

    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
  5. Open the block mask dialog box to verify the addition of the new pinNumber field.

In the next section, you will Add Push Button to View Pin Map to your MATLAB System block dialog mask.

See Also

| |