主要内容

Design Custom Displays

This example shows how to use the Display block from the Customizable Blocks library to design two displays:

  • An odometer

  • A thermostat display

The blocks in the model use PNG images as the background for the displays. You can find all images used to create the displays in the example directory, in the CustomDisplayImages folder.

Odometer and thermostat display

Design Odometer

To design the odometer, add a customizable Display block to the model using the Simulink® quick insert menu:

  1. To open the quick insert menu, double-click in the canvas.

  2. To search for the customizable Display block, type Display.

  3. Select the search result with the library path Simulink/Dashboard/Customizable Blocks.

To customize the Display block, enter design mode:

  1. In the model canvas, select the block.

  2. In the Simulink Toolstrip, click the Display tab.

  3. On the Display tab, click Edit. A toolbar with customization options appears above the block.

  4. You can also customize the block using the Design tab of the Property Inspector. To open the Design tab, in the toolbar above the block, click Open Design Tab.

In this example, you use both the toolbar and the Design tab to customize the block.

Display block in design mode with the Design tab of the Property Inspector open

Add the background image for the odometer:

  1. In the toolbar above the Display block, click the Replace Background Image button.

  2. In the CustomDisplayImages folder, select the odometer-background.png file.

Display block in design mode with the toolbar above the block displaying the tooltip Replace Background Image above the leftmost toolbar button

Increase the size of the odometer.

  1. Exit design mode. In the Property Inspector, on the Design tab, click Edit.

  2. Drag a corner of the block outward until the text ODO is large enough to read.

Resized Display block

In the model, the output signal of a Ramp block represents the current odometer reading. The output port of the Ramp block connects to a signal line named odometer. Connect the Display block to the signal line to see how the displayed value looks during simulation.

  1. Select the Display block.

  2. Click the Connect button that appears above the block.

  3. Select the signal line named odometer.

  4. Select the odometer option in the table that appears below the selected signal.

  5. Click the X in the upper-right corner of the Simulink window.

Selected Display block with the Connect button displayed above the block

The signal line named odometer is selected in the model diagram. A table is displayed below the selected signal. In the table, the signal named odometer is selected.

Simulate the model. This model uses simulation pacing to slow model execution so you can clearly see the displayed value changing during simulation. For more information about simulation pacing, see Simulation Pacing Options.

Display block during simulation, with the displayed font small and yellow

Customize the font.

  1. Enter design mode. Select the Display block. In the Property Inspector, on the Design tab, click Edit.

  2. In the toolbar above the block, click the Set Color button and select black.

  3. Set the font size to 48.

  4. Make the font bold by selecting B.

  5. In the Property Inspector, on the Design tab, select the Text component. In the Size and Position section, adjust the X Offset value such that the right edge of the displayed number is at the right edge of the block.

  6. Adjust the Y Offset value such that the bottom of the displayed number lines up with the bottom of the ODO text.

Display block in design mode, with the font size set to 48, the text in bold, and the text position offset

Exit design mode. In the Property Inspector, on the Design tab, click Edit.

To use the finished odometer, run the simulation again and observe the displayed odometer reading change over time.

Finished odometer during simulation with the connected model diagram

Design Thermostat Display

Design a thermostat display that shows these four values:

  • Room temperature

  • Room humidity

  • Outside temperature

  • Outside humidity

Add a customizable Display block to the model using the Simulink quick insert menu:

  1. To open the quick insert menu, double-click in the canvas.

  2. To search for the customizable Display block, type Display.

  3. Select the search result with the library path Simulink/Dashboard/Customizable Blocks.

In the model, the current temperature and humidity readings are each represented by the output signal of a Ramp block. Connect the Display block to the signal line named T_room to see how the displayed value looks during simulation.

  1. Select the Display block.

  2. Click the Connect button that appears above the block.

  3. Select the signal named T_room.

  4. In the table that appears below the selected signal, select T_room.

  5. Click the X in the upper-right corner of the Simulink window.

Selected Display block with the Connect button displayed above the block

The signal line named T_room is selected in the model diagram. A table is displayed below the selected signal. In the table, the signal named T_room is selected.

Simulate the model. This model uses simulation pacing to slow model execution to see the displayed value changing during simulation. For more information about simulation pacing, see Simulation Pacing Options.

Display block during simulation, with the displayed font in yellow

To customize the Display block, enter design mode:

  1. In the model canvas, select the block.

  2. In the Simulink Toolstrip, click the Display tab.

  3. On the Display tab, click Edit. A toolbar with customization options appears above the block.

  4. You can also customize the block using the Design tab of the Property Inspector. To open the Design tab, in the toolbar above the block, click Open Design Tab.

In this example, you use both the toolbar and the Design tab to customize the block.

Display block in design mode with the Design tab of the Property Inspector open

Customize the font.

  1. In the toolbar above the Display block, change the font to Roboto.

  2. Click the Set Color button and select the blue color with the RGB values [0.18 0.75 0.94]. To see the RGB value of a color, pause on the color.

The Display block is in design mode. In the toolbar above the block, the Set Color button is pressed, and the blue color is selected.

Display block after selecting the blue color

Remove the block background image. In the Property Inspector, on the Design tab, select the Background Image component. In the Select Image section, click X.

Exit design mode. In the Property Inspector, on the Design tab, click Edit.

Display block without the background image

Add units to the displayed value.

  1. In the Property Inspector, on the Parameters tab, set Format to Custom.

  2. Set Format String to %d °C.

  3. Press Enter.

Display block displaying the value 26 °C

Create three copies of the block. Position the four blocks in a grid, with the original in the upper-left corner.

Four copies of the Display block arranged in a grid

Change the connections of the blocks in the lower-left, upper-right, and lower-right positions. For each block:

  1. Select the block.

  2. Pause on the ellipsis (...) that appears.

  3. In the action menu that expands, click Connect.

  4. To connect the signal in the lower left, select the signal named h_room. To connect the signal in the upper right, select the signal named T_outside. To connect the signal in the lower right, select the signal named h_outside.

  5. In the table that appears below the selected signal, select the option with the same name as the signal line that you selected.

  6. Click the X in the upper-right corner of the Simulink window.

Promote all four blocks to a panel. Drag to select the blocks, then pause on the ellipsis (...) that appears. In the action bar that expands, click Promote to Panel.

The grid of Display blocks is selected. The action bar is displayed at the lower right of the grid. In the action bar, the rightmost button is highlighted and shows the tooltip Promote to Panel.

The four Display blocks in a dashboard panel

Add a background image to the panel.

  1. Enter edit mode. Select the panel. Pause on the ellipsis (...) that appears. In the action bar that expands, click Edit Panel.

  2. In the action bar above the block, click Change Background Image. In the CustomDisplayImages folder, select the thermostat-background.png file.

The panel has a background image. The background image shows a table with four cells. The left column is labeled Room, and the right column is labeled Table. The lower left cell contains the text % Humidity. All other cells are empty. The background image is vertically compressed.

Resize the panel to roughly the dimensions shown, such that the text in the background image is clearly visible and neither stretched nor compressed.

The panel is large enough that the background image is not vertically compressed.

Move the block in the upper-left position into the upper-left cell of the table in the panel background image. Move the block in the lower-left position into the lower-left cell, the block in the upper-right position into the upper-right cell, and the block in the lower-right position into the lower-right cell.

If you drop a block when any part of the block is outside of the panel, the block drops onto the model canvas instead of onto the panel. To return the block to the panel, move the panel aside so that you can see the block. Move the panel by clicking and dragging any part of the panel where there is no block. Then, drag the block back onto the panel, and make sure that the block is completely on the panel before you drop the block.

Panel with each Display block in a cell of the table in the background image

Resize the panels by dragging and pressing Shift. Resize the blocks such that the blocks are the same size as their cells. Then, horizontally resize the block in the lower-left cell such that the right-edge of the block touches the left edge of the text Humidity in the cell.

Panel with the resized Display blocks

Configure the block in the upper left cell.

  1. Exit edit mode by clicking anywhere on the model canvas.

  2. Enter design mode. Select the block. In the Property Inspector, on the Design tab, click Edit.

  3. In the toolbar above the block, increase the font size such that the displayed value fills the cell. To enter a custom font value, double-click the font size displayed in the toolbar, type a new value, and press Enter.

  4. Make the font bold by selecting B.

Panel with the Display block in the upper left cell in design mode, the font size set to 130, and the displayed text in bold

Configure the block in the lower-left cell. Resize the font of the value displayed by the block in the lower-left cell to be about two thirds the size of the font of the value displayed by the block in the upper-left cell. To resize the font, click the block and adjust the font size in the toolbar above the block.

Panel with the Display block in the lower left cell in design mode and the font size set to 86

Configure the blocks in the upper- and lower-right cells. Resize the font of the values displayed by the blocks to about a quarter as big as the font of the value displayed by the block in the upper-left cell. To resize the font, click the block and adjust the font size in the toolbar above the block.

Panel with the Display block in the lower right cell in design mode and the font size set to 33

Exit design mode. In the Property Inspector, on the Design tab, click Edit.

In the values displayed by the two blocks in the bottom cells, change °C to %. For each block:

  1. Select the block.

  2. In the Property Inspector, on the Parameters tab, set Format String to %d%%.

  3. Press Enter.

To use the finished thermostat, run the simulation and observe the displayed temperature and humidity readings change over time.

Finished thermostat display during simulation with the connected model diagram

If you have not already done so, try moving the panel by clicking and dragging any part of the panel where there are no blocks. The panel floats above the model canvas. Then, drag the model canvas. The model canvas moves, but the panel stays in place. Panels allow you to monitor signals while moving through a model.

You can open a panel in a separate window from the model. Select the panel. Pause on the ellipsis (...) that appears. In the action bar that expands, click Open In New Window.

Action bar with the tooltip Open In New Window above the third button from the left

Panel open in its own window

You can use the toolbar at the top of the new window to start, stop, and pause the simulation.

To return the panel to the Simulink Editor, in the toolstrip of the new window, click Open in canvas.

Toolbar at the top of the panel open in its own window, with the tooltip Open in canvas displayed below the rightmost button

See Also

Blocks

Topics