MATLAB Examples

getButton

Get the status of the button on Engduino whether it is pressed or released.

Contents

Syntax

status = e.getButton();

Description

e.getButton() Get the state of the button on Engduino, function return true or false

Examples

  • Turn on LED when button is pressed
  • Connect to Engduino, turn on LED when button pressed

    % Check if the Engduino object already exists. Otherwise initialize it.
    if (~exist('e', 'var'))
            e = engduino();
    end
    
    while (true)
        % read the status of the button
        status = e.getButton()
        if status
            % turn on LED
            e.setLed(1);
        else
            % turn off LED
             e.setLed(0);
        end
    end
    

    Input Arguments

    No input arguments.

    Output Arguments

    status Return button state. 1 - is pressed, 0 - otherwise