Documentation search search close
CONTENTS

    Open this example in MATLAB

v10.0.1.x for R2026a
View other versions

Utilities - Read Button Press

This example demonstrates how to use the Read Button Press block from the Speedgoat I/O Blockset Utilities library.
This block allows reading the state of the User button present on every Speedgoat Pulse real-time target machine, as well as the state of keyboard keys from a USB or PS/2 keyboard connected to the real-time target machine.
The Simulink® model features the Read Button Press block from the Speedgoat Utilities library.

Setup

Prerequisites

You will require the following to run this example:
  • Speedgoat real-time target machine
  • A USB keyboard attached to the target machine's USB port

Initialize and Open the Simulink Model

% Open Simulink model
modelName = 'sgMdl_Utilities_ReadButtonPress';
open_system(modelName);

Build, Download, and Run the Example

To run the example, either run the following code section or click the Run on Target button in the REAL-TIME tab in the Simulink model.
% Build the Simulink model
slbuild(modelName); % this will create the real-time application file (.mldatx)
 
% Create and connect to the Speedgoat real-time target machine
tg = slrealtime;
tg.connect;
 
% Download the real-time application to the target machine and set stop time
tg.load(modelName);
 
% Connect the Simulink model with external mode to the real-time application on the target machine
set_param(modelName, 'SimulationMode', 'external') % put model into External Mode
set_param(modelName, 'SimulationCommand', 'connect') % connect with External Mode
 
% Start the real-time application and open the SDI-Viewer
tg.start;
View the output directly in the Simulink Editor while the model is running in external mode.
The different actions linked to each button press are intended as examples showcasing how the Read Button Press block can be used in various modeling workflows.
Pressing the respective keyboard keys or the User button on the Pulse real-time target machine has the following effects:
  • User button: View state changes on the display
  • Enter key: Enable/disable file logging. The logged signal is the User button state
  • Space key: Switch between two parameter values and view the output on the display
  • 'A' key: Trigger execution of an asynchronous subsystem containing a free-running counter
  • 'B' key: Switch between two enabled subsystems containing a free-running counter
  • 'Q' key: Stop the real-time application

Additional References