Home Examples Task Control Buttons

Task Control Buttons

For some tasks it is useful to have the operator able to provide input in order to mark events or advance trials. A task can define buttons that are displayed in Dexterit-E. The buttons are defined within the Parameter Table Defn block. Button clicks during task execution are recorded automatically in the data files as Task Event Codes with the name “TASK_BUTTON_[id]_CLICKED”. Here is an example of defining buttons (assuming the Task Event Code definitions in 10.1.2 Parameter Table Defn Block for Task Event Codes Example).  This example includes a Sample Task: Task Control Button available for download.

Figure 10.4: Defining Task Control buttons.

The variables in the interface have the following meanings:

  • Btn# – This is an identifier for the button. If buttons are not given group and layout information they are placed in the GUI in order of ascending index. Button numbers may be any value from 2 to 254.
  • Constant Name – A name that can be used within any Stateflow code, or in Simulink blocks as described in Section 3.12.
  • Button Label – The text that will appear on the button in the GUI. This is also the string used in both Dexterit-E and data files to record and identify the Task Event Code when the button is clicked.
  • Enable Event Codes – A comma separated list of defined Task Event Codes that will cause the button to enable. If the field is blank then the button is enabled by default.
  • Disable Event Codes – A comma separated list of defined Task Event Codes that will cause the button to disable.
  • Button Group – Allows the grouping and laying out of buttons (see description below).
  • Parameter Description – The text that will appear beside the button in the GUI.

In order to make use of clicks of your defined buttons you will need to use a From tag in your Simulink code. In the From tag dialog, select task_control_button. When the operator clicks a Task Control Button in the Dexterit-E user interface, the From tag in Simulink will output the value of the button # for 1 ms. The rest of the time the From tag will output a zero.

Below is an example of a simple button which when clicked will produce a Simulink event that can drive a Stateflow chart (e.g. to advance to the next trial within the Stateflow chart). In the Simulink code the button click is used to drive a Stateflow event. Because the task_control_button From tag holds its value for 1 ms it can also be used as a normal data input to the Stateflow chart.

Figure 10.5: Example Task Control Button in the GUI.

Figure 10.6: Using a Task Control Button in Simulink

10.2.1   Grouping Task Control Buttons in Dexterit-E

You can group several Task Control Buttons together using the Button Group column in the Task Control buttons tab of the Parameter Table Defn block. The format of the button group string is:

[Group ID],[rows]x[cols],[position]


  • Group ID – any integer. All buttons defined within the same group ID are considered part of the same group.
  • rows – the number of rows in the grid that is used to lay out the group of buttons.
  • cols – the number of columns in the grid that is used to lay out the group of buttons.
  • position – the position in the grid where the button should be placed. 1 is the top left corner.

For example, if the rows and columns are defined as 3×4, the possible positions on the grid are:

Table 10.1: Example Button Layout

1 2 3 4
5 6 7 8
9 10 11 12

Buttons defined at position 0 become the optional label for the group of buttons. Figure: 10.7 and Figure: 10.8 show an example of a more complex button layout. This example includes two button groups and one solitary button. If no button is defined at a position then that position is considered empty and is drawn in the normal background colour of Dexterit-E.

Figure 10.7: Parameter Table Definition of Button Layout

Based on the layout defined above, the buttons would appear in Dexterit-E as:

Figure 10.8: Button Layout in Dexterit-E

Related Tasks

Coding Tips
Persistent Variables
Persistent variables are ones that hold their value between calls to the embedded MATLAB code they are defined in.
Coding Tips
Custom Control of the Trial Protocol Order
Normally, Dexterit-E manages and controls the order in which Trial Protocols (TPs) execute based on what is defined in the block table of the Task Protocol (see the Dexterit-E User Guide for more details).