Main Content

Create or Open a MATLAB Function

Create or open a MATLAB® function in the Editor. Create the function by following the guidelines described in MATLAB Code Design Considerations for Code Generation (MATLAB Coder). This workflow uses a function called blinkLED as an example. You can use the same steps with your own function.

Note

The MATLAB function to be deployed on the hardware must not have any input or output arguments. MATLAB functions with input or output arguments are not supported for deployment.

  1. Copy the blinkLED function and paste it in the MATLAB Editor. The function implements an algorithm to blink the ACT LED on the Raspberry Pi® hardware every 0.5 seconds for 100 cycles.

    function blinkLED()
    
    % Create a Raspberry Pi object
    r= raspi();
    
    % Blink the LED for 100 cycles
    for count = 1:100
        % Turn on the LED
        writeLED(r,"LED0", 1);
        % Pause for 0.5 seconds
        pause(0.5);
        % Turn off the LED
        writeLED(r,"LED0", 0);
        % Pause for 0.5 seconds
        pause(0.5);
    end
    end
  2. Save the example function to a folder to which you have write access.

Related Topics