Main Content

Lamp

Display color that reflects signal value on lamp with customizable appearance

Since R2021b

  • Lamp block

Libraries:
Simulink / Dashboard / Customizable Blocks

Description

The Lamp block displays a color that reflects the value of the connected signal. When you use the Lamp block in the Customizable Blocks library, you can modify the appearance of the block so it looks like a real indicator lamp in your system. Use the Lamp block with other dashboard blocks to build an interactive dashboard of controls and indicators for your model.

To configure the Lamp block, specify one or more states. A state pairs a state value with a color for the Lamp block to display. When the value of the connected signal is the same as the state value, the Lamp block displays the color. You can also specify the state value as a range, such that the block displays the color when the value of the connected signal falls into the specified range.

Customize Lamp Blocks

When you add a Lamp block to your model, the block is preconfigured with a default design. You can use the block with the default design or customize the appearance of the block.

To customize the appearance of the block, use design mode. After selecting the block, you can enter design mode in one of three ways:

  • In the Simulink® Toolstrip, on the block-specific tab, under Design, click Edit.

  • In the Property Inspector, on the Design tab, click Edit.

  • Pause on the ellipsis that appears over the block and click the Edit Custom Block button .

In design mode, you can use the toolbar above the block to customize the lamp. To access additional customization options or to enter exact values for design settings, use the Design tab in the Property Inspector.

Customizable Lamp block in design mode with the toolbar and the Design tab in the Property Inspector visible.

When you customize a Lamp block, you configure the block appearance for each state. To select a state to customize, use the drop-down list in the toolbar. Alternatively, on the Design tab, select the States component, and then select from the Select State list. To add a state, in the toolbar, click the Add State button . To delete a state, click the Remove State button .

Design Mode Actions that Customize the Selected State

ActionAvailable in ToolbarAvailable in Design Tab

Specify the state value as a number or a range.

NoYes

Select a shape for the region whose color reflects the signal value.

YesYes

Select the color of the shape.

YesYes

Select from an icon set that includes wireless icons and automotive indicator lamps, or upload a custom icon.

YesYes

Specify how to combine the shape and the icon.

YesYes
Change the size of the shape and icon.NoYes
Change the position of the shape and icon.NoYes

In addition to customizing the block design using the toolbar and Design tab, you can also resize and reposition components interactively in the canvas. To resize a component specific to a state, such as the icon, select the state in the toolbar, and then resize or reposition the component.

To combine the shape and icon, in the third section of the toolbar from the left, choose one of these combination styles:

  • Simple — Overlay the icon on top of the shape.

  • Intersect — Retain the intersection of the shape and icon as the area whose color reflects the signal value.

  • Subtract — Retain the shape with the icon cut out of it as the area that changes color.

Three Lamp blocks, each configured for one of the three ways you can combine the shape and icon: simple, intersect, or subtract.

Tip

The intersect and subtract combination styles use transparency in the icon asset to produce the area that changes color. For custom icons, consider using image formats that support transparency, such as SVG or PNG.

Design Mode Actions that Apply to All States

ActionAvailable in ToolbarAvailable in Design Tab

Upload a background image.

NoYes

Set a solid background color.

NoYes

Upload a foreground image.

NoYes

When you finish editing the design, to exit design mode, click the X in the upper right of the canvas.

Connect Dashboard Blocks

Dashboard blocks do not use ports to connect to model elements. To connect a dashboard block, use connect mode. To enter connect mode on an unconnected block, pause on the block you want to connect and click the Connect button . To enter connect mode on a connected block, select the block, pause on the ellipsis that appears (…), and in the action menu that expands, click the Connect button.

To connect a display block to a signal in your model or change the connection of a display block, enter connect mode. Select the signal line to which you want to connect. From the list that appears, select the signal to which you want to connect. Then, pause on the dashboard block and click the Done Connecting button . To see the dashboard block display the value of the connected block, run the simulation.

For more information about connecting dashboard blocks, see Connect Dashboard Blocks to Simulink Model.

You can also connect dashboard blocks to a Stateflow® chart. For more information, see Connect Dashboard Blocks to Stateflow (Stateflow).

This animation shows how to connect the Lamp block to your model.

An unconnected Lamp block connects to the signal that a Constant block sends to an Outport block.

Examples

Limitations

  • Except for the Dashboard Scope block and the Display block, dashboard blocks can only connect to real scalar signals.

  • You cannot use the Connection table in the Block Parameters dialog box to connect a dashboard block to a block that is commented out. When you connect a dashboard block to a commented block using connect mode, the dashboard block does not display the connected value until the you uncomment the block.

  • Dashboard blocks cannot connect to model elements inside referenced models.

  • When you simulate a model hierarchy, dashboard blocks inside referenced models do not update.

  • Dashboard blocks do not support rapid accelerator simulation.

  • During simulation, you cannot connect a dashboard block to Stateflow chart data or state activity.

  • You cannot programmatically connect a dashboard block to Stateflow chart data or state activity.

  • Some signals do not have data available during simulation due to block reduction or optimization for accelerator mode simulations. To view such a signal using a dashboard block, mark the signal for logging.

Parameters

expand all

Use the Property Inspector and the Block Parameters dialog box to specify the values of the block parameters. To set the core parameters of the dashboard block, use the Block Parameters dialog box or the Parameters tab in the Property Inspector. To customize the block, use the Design tab in the Property Inspector. To open the Block Parameters dialog box for a block, double-click the block. To open the Property Inspector, on the Modeling tab, under Design, select Property Inspector.

Parameters

To set the core parameters of the dashboard block, open the Property Inspector and click the Parameters tab.

Signal

Dashboard blocks do not use ports to connect to model elements. To connect dashboard blocks to parameter values in your model, use connect mode, the Simulink Toolstrip, or the Connection table in the Block Parameters dialog box. For information about connect mode and how to connect using the toolstrip, see Connect Dashboard Blocks to Simulink Model.

To connect a display block or change the connection of a display block using the Connection table:

  1. Select the block.

  2. To connect the block, in the Property Inspector, on the Parameters tab, click Connect. To change the connection of the block, click Change instead.

  3. Select the signal line to which you want to connect.

  4. In the table, select the signal to which you want to connect.

  5. Click Apply.

You can also connect dashboard blocks to a Stateflow chart. For more information, see Connect Dashboard Blocks to Stateflow (Stateflow).

Programmatic Use

Block Parameter: Binding
Type: Simulink.HMI.SignalSpecification
Default: []
Main

You can display the name of the element to which the dashboard block connects in a label positioned at the top or bottom of the block, or you can hide the label. If you want the label to be visible, specify the position. If you do not want the label to be visible, select Hide.

Note

When the dashboard block is not connected to an element, the label is blank.

Programmatic Use

Block Parameter: LabelPosition
Type: character vector
Values: 'Hide' | 'Bottom' | 'Top'
Default: 'Hide'

Select this parameter to maintain the aspect ratio when resizing the block in the Simulink canvas.

When the aspect ratio is locked, adding a new background image changes the aspect ratio of the block to match the aspect ratio of the background image. When the aspect ratio is unlocked, adding a new background image does not change the aspect ratio of the block, but instead changes the aspect ratio of the background image to fit the size of the block.

When the aspect ratio is locked, pressing the Shift key while resizing a block temporarily unlocks the aspect ratio. When you release the Shift key, the aspect ratio locks. When the aspect ratio is unlocked, pressing the Shift key while resizing a block temporarily locks the aspect ratio. When you release the Shift key, the aspect ratio unlocks.

States

You can specify ranges of signal values that activate the Lamp block states. Select Specify State Values as Ranges and specify the minimum and maximum of the value range that activates each state.

Programmatic Use

To programmatically specify whether the states are each activated by a signal value or by a range of signal values, specify the StateValueType parameter as a string or a character vector. To activate each state with a signal value, set StateValueType to "Discrete". To activate each state with a range of signal values, set StateValueType to "Range".

Block Parameter: StateValueType
Type: character vector | string
Values: "Discrete" | "Range"
Default: "Discrete"

States pair a lamp color with a value of the connected signal. Each state consists of a Color and a State.

  • State — Connected signal value or range of signal values that cause the Lamp block to display the specified color. To specify a range of values, select Specify State Values as Ranges and specify the minimum and maximum of the range of values that activates each state.

  • Color — Lamp color when the connected signal value matches the corresponding State value. You can select from a palette of standard colors or specify a custom color with RGB values.

The [undefined] state specifies the color of the Lamp block when the connected signal value does not match any of the values specified in the States table. Click the + button to add another state.

Programmatic Use

To programmatically specify the State and Color parameter values for a Lamp block, use an array of structures that contain these fields:

  • Value — Scalar double signal value or vector specifying the minimum and maximum of a range of double signal values that cause the Lamp block to display the specified color indication.

    Note

    Specifying a vector enables the Specify State Values as Ranges option.

  • Color1-by-3 [r g b] vector with values between 0 and 1 that specifies the color for the Lamp block to display.

lampState1.Value = [1 2];
lampState1.Color = [0 0 1];
lampState2.Value = [2 3];
lampState2.Color = [1 0 0];
lampStates = [lampState1 lampState2];
Block Parameter: StateColors
Type: structure array
Default: structure

The ColorDefault parameter specifies the color for the Lamp block when the value of the connected signal does not match any of the specified state values. Specify the ColorDefault parameter as a 1-by-3 [r g b] vector with values between 0 and 1.

Block Parameter: ColorDefault
Type: [r g b] vector
Default: [0.7529 0.7529 0.7529]

Design

To customize the dashboard block, open the Property Inspector, click the Design tab, and click Edit.

Lamp

Select this parameter to maintain the aspect ratio when resizing the block in the Simulink canvas.

When the aspect ratio is locked, adding a new background image changes the aspect ratio of the block to match that of the background image. When the aspect ratio is unlocked, adding a new background image does not change the proportions of the block but instead stretches or scales the background image to fit the size of the block.

When the aspect ratio is locked, pressing the Shift key while resizing a block unlocks the aspect ratio. When you release the Shift key, the aspect ratio locks. When the aspect ratio is unlocked, pressing the Shift key while resizing a block locks the aspect ratio. When you release the Shift key, the aspect ratio unlocks.

States

Select a state that you want to configure from the drop-down menu in the Select State section of the States component. You can use a customizable Lamp block to design a lamp with any number of states greater than or equal to 1. Click + to add another state. Click X to delete the current state.

States match a display color to the value of the connected signal. Each state consists of a State and a Color.

  • State — Connected signal value or range of signal values that cause the Lamp block to display the specified color. To specify a range of values, select Specify State Values as Ranges and specify the minimum and maximum of the range of values that activates each state.

  • Color — Lamp color when the connected signal value matches the corresponding State value. You can select from a palette of standard colors or specify a custom color with RGB values.

The [default] state specifies the color of the Lamp block when the connected signal value does not match any of the values specified in the States table.

Note

You can configure more than the value and color of a state: you can configure all of the parameters in the States component of the Design tab for a state. For example, you can select an icon that will appear on the lamp when it is in the state. When you configure any of the parameters in the States component, the changes are applied to the state that is selected in the Select State section of the States component.

Tips

You can also configure the values and colors of the states for the block using the Parameters tab in the Property Inspector.

Programmatic Use

To programmatically specify the State and Color parameter values for a Lamp block, use an array of structures that contain these fields:

  • Value — Scalar double signal value or vector specifying the minimum and maximum of a range of double signal values that cause the Lamp block to display the specified color indication.

    Note

    Specifying a vector enables the Specify State Values as Ranges option.

  • Color1-by-3 [r g b] vector with values between 0 and 1 that specifies the color for the Lamp block to display.

lampState1.Value = [1 2];
lampState1.Color = [0 0 1];
lampState2.Value = [2 3];
lampState2.Color = [1 0 0];
lampStates = [lampState1 lampState2];
Block Parameter: StateColors
Type: structure array
Default: structure

The ColorDefault parameter specifies the color for the Lamp block when the value of the connected signal does not match any of the specified state values. Specify the ColorDefault parameter as a 1-by-3 [r g b] vector with values between 0 and 1.

Block Parameter: ColorDefault
Type: [r g b] vector
Default: [0.7529 0.7529 0.7529]

Apply the settings of the default state to all other states. This option applies to all settings in the States component except for the settings in the Value and Color section.

You can specify ranges of signal values that activate the states. Select Specify State Values as Ranges and specify the minimum and maximum of the value range that activates each state.

Programmatic Use

To programmatically specify whether the states are each activated by a signal value or by a range of signal values, specify the StateValueType parameter as a string or a character vector. To activate each state with a signal value, set StateValueType to "Discrete". To activate each state with a range of signal values, set StateValueType to "Range".

Block Parameter: StateValueType
Type: character vector | string
Values: "Discrete" | "Range"
Default: "Discrete"

Each state pairs a Value with a Color. Specify the Value that activates the state selected in the Design tab.

Note

When the Specify State Values as Ranges option is enabled, the Value parameter changes to the parameters Minimum and Maximum, which allow you to define a range by specifying its minimum and maximum values.

Example: 0

Each state pairs a Value with a Color. Choose the Color of the state selected in the Design tab from the palette of standard colors, or specify a custom color.

Example: [1 0 0]

Specify the opacity of the state Color as a scalar value from 0 to 1.

Example: 0.5

A lamp can show up to three different colors:

  • State Color

  • Color of the selected icon in the Property Inspector

  • Background color or the background image, depending on which is activated

The colors that show on the lamp depend on how the shape and icon layers of the Lamp block are combined. Select how to combine the layers:

  • In the Intersect style, the area where the shape and icon overlap has the state Color. The area where the shape and icon do not overlap has the background color or image.

  • In the Simple style, the area of the shape that is not covered by the icon has the state Color. The icon on the lamp has the same colors as its counterpart in the Property Inspector. The remaining area has the background color or image.

  • In the Subtract style, the area of the shape that is not covered by the icon has the state Color. The remaining area has the background color or image.

Three Lamp blocks, each configured for one of the three ways you can combine the shape and icon: simple, intersect, or subtract.

Example: 'Simple'

Select a shape that, in combination with the icon, determines the area on the lamp to which the state Color is applied. Choose a circle, a square, or a triangle.

Use an icon to configure the appearance of the Lamp block in the model. You can choose from built-in shape, automotive, and wireless icons, or you can upload your own custom SVG file as an icon.

To view icon options, in the Icon section, select an Icon Type. To use your own SVG file as the block icon, in the Icon section, select Custom as the Icon Type, and in the Custom Icon section, click the plus button to upload the SVG file.

Shape Icons

IconIcon NameProgrammatic Use Value

Lamp icon: a solid gray circle

LampDefault

Check1 icon: a check mark

Check1Check1

Check2 icon: a check mark with slightly curved lines

Check2Check2

Check3 icon: the outline of a check mark

Check3Check3

Check4 icon: a check mark with a divot along its outline

Check4Check4

Circle icon: a solid black circle

CircleCircle

Ex1 icon: a cross mark

Ex1Ex1

Ex2 icon: a cross mark with one curved line

Ex2Ex2

Ex3 icon: the outline of a cross mark

Ex3Ex3

Ex4 icon: a cross mark with a divot along the outline

Ex4Ex4

Face icon: the outline of a face with a closed mouth in a straight line

FaceFace

Frown1 icon: the outline of a face with an open frowning mouth

Frown1Frown1

Frown2 icon: the outline of a face with a closed frowning mouth

Frown2Frown2

Hexagon icon: a solid hexagon

HexagonHexagon

L-shaped membrane icon: the silhouette of the L-shaped membrane

L-shaped MembraneMembrane

Pentagon icon: a solid pentagon

PentagonPentagon

Rectangle icon: a solid rectangle

RectangleRectangle

Smile1 icon: the outline of a face with an open upturned mouth

Smile1Smile1

Smile2 icon: the outline of a face with a closed upturned mouth

Smile2Smile2

Solid Face icon: a solid face with a closed mouth in a straight line

Solid FaceSolidFace

Solid Frown1 icon: a solid face with an open frowning mouth

Solid Frown1SolidFrown1

Solid Frown2 icon: a closed frowning mouth

Solid Frown2SolidFrown2

Solid Smile1 icon: a solid face with an open upturned mouth

Solid Smile1SolidSmile1

Solid Smile2 icon: a solid face with a closed upturned mouth

Solid Smile2SolidSmile2

Square icon: a solid square

SquareSquare

Triangle icon: a solid triangle

TriangleTriangle

Automotive Icons

IconIcon NameProgrammatic Use Value

Adaptive Cruise Control icon: a speedometer with an arrow pointing to a tick mark, and the silhouette of a car in the background

Adaptive Cruise ControlAdaptiveCruiseControl

Adaptive Cruise Control Failure icon: a speedometer with an exclamation mark next to it, and the silhouette of a car in the background

Adaptive Cruise Control FailureAdaptiveCruiseControlFailure

ABS icon: a circle labeled "ABS" in a set of parentheses

Antilock Brake SystemAntilockBrakeSystem

Battery icon: the outline of a battery, with a + symbol on the positive pole, and a - symbol on the negative pole

BatteryBattery

Check Engine icon: the outline of an engine labeled "Check Engine"

Check EngineCheckEngine

Check Engine2 icon: the outline of an engine with the silhouette of a lightning rod on it, and the word "CHECK" underneath it

Check Engine2CheckEngine2

Cruise Control icon: a speedometer with an arrow pointing to one of the tick marks

Cruise ControlCruiseControl

Eco Mode icon: a solid leaf shape labeled "ECO"

Eco ModeEcoMode

Electronic Stability icon: a circle labeled "ESP" in a set of parentheses

Electronic StabilityElectronicStability

Engine icon: the silhouette of an engine

EngineEngine

Engine Coolant Temp icon: a thermometer with waves in the background

Engine Coolant TempEngineCoolantTemp

Engine Failure icon: the silhouette of an engine with an exclamation mark on it

Engine FailureEngineFailure

Engine Heating icon: the silhouette of an engine with three wavy arrows pointing upwards on it

Engine HeatingEngineHeating

Engine Oil icon: the silhouette of an oil can

Engine OilEngineOil

Exterior Bulb Failure icon: the silhouette of a glowing light bulb with an exclamation mark on it

Exterior Bulb FailureExteriorBulbFailure

Front Fog Light icon: the outline of a fog light lamp emitting rays of light to the left that are depicted as diagonal lines on top of a wavy vertical line that represents the fog

Front Fog LightFrontFogLight

Fuel icon: the silhouette of a gas pump with an arrow pointing left on it

FuelFuel

Hazards icon: the outline of a warning triangle

HazardsHazards

Headlamp Leveling icon: the outline of a lamp emitting rays of light with an arrow pointing clockwise above them and an arrow pointing counterclockwise below them to indicate that the lamp can be turned to level the light rays

Headlamp LevelingHeadlampLeveling

High Beams icon: the outline of a lamp emitting horizontal rays of light

High BeamsHighBeams

Hill Descent Control icon: the outline of a car driving down a slope

Hill Descent ControlHillDescentControl

Lighting Switch icon: the silhouette of a glowing light bulb

Lighting SwitchLightingSwitch

High Beams icon: the outline of a lamp emitting rays of light that run diagonally downward

Low BeamsLowBeams

Parking Assistance icon: the letter "P" next to a solid triangle that represents an obstacle, and the "P" emits a detection signal represented as three curved lines aimed at the triangle

Parking AssistanceParkingAssistance

Rear Fog Light icon: the outline of a fog light lamp emitting rays of light to the right that are depicted as horizontal lines on top of a wavy vertical line that represents the fog

Rear Fog LightRearFogLight

Side Lights icon: the outline two lamps emitting rays of light to the left and right

Side LightsSideLights

Stability Control icon: the silhouette of a car with wavy lines behind it to represent the car slipping

Stability ControlStabilityControl

Stability Control Off icon: the silhouette of a car with wavy lines behind it to represent the car slipping, and the word "OFF" underneath

Stability Control OffStabilityControlOff

Tire Monitor icon: the outline of the cross-section of a tire with an exclamation mark on it

Tire MonitorTireMonitor

Traction Control icon: the outline of the cross-section of a tire with the label "TC"

Traction ControlTractionControl

Traction Control Off icon: the outline of the cross-section of a tire with the label "TC" and a diagonal slash through the whole image

Traction Control OffTractionControlOff

Traction Control Failure icon: the outline of the cross-section of a tire with the label "TC" and an exclamation mark next to it

Traction Control FailureTractionControlFailure

Turn Signal Left icon: a solid arrow pointing left

Turn Signal LeftTurnSignalLeft

Turn Signal Right icon: a solid arrow pointing right

Turn Signal RightTurnSignalRight

Wireless Icons

IconIcon NameProgrammatic Use Value

Network icon: the wireless internet connection icon

NetworkNetwork

Network No Signal icon: the wireless internet connection icon grayed out, with a crossed-out circle next to it

Network No SignalNetworkNoSignal

Network Transmission icon: a wireless internet tower

Network TransmissionNetworkTransmission

Network3G icon: the wireless internet connection icon with "3G" next to it

Network3GNetwork3G

Network4G icon: the wireless internet connection icon with "4G" next to it

Network4GNetwork4G

Network5G icon: the wireless internet connection icon with "4G" next to it

Network5GNetwork5G

Tip

The Dashboard library has libraries with a preconfigured Lamp block for each icon.

Programmatic Use

Block Parameter: Icon
Type: string | character vector
Default: 'Default'

Specify the horizontal offset of the left edge of the bounding box of the shape and icon combination from the left edge of the block as a ratio of the block width. Relative to the position of the shape and icon combination when the offset is 0, an offset with a negative value moves the combination left and an offset with a positive value moves the combination right.

Example: 1

Specify the vertical offset of the top edge of the bounding box of the shape and icon combination from the top edge of the block as a ratio of the block height. Relative to the position of the shape and icon combination when the offset is 0, an offset with a negative value moves the combination up and an offset with a positive value moves the combination down.

Example: 1

Specify the width of the bounding box of the shape and icon combination as a ratio of the block width.

Example: 0.5

Specify the height of the bounding box of the shape and icon combination as a ratio of the block height.

Example: 0.5

You can modify how the icon is shown on the lamp by zooming in or out on its center. Specify the zoom level as a scalar value from 0 to 2. When the Icon Size is 1, the icon is zoomed to show the whole image as large as is possible within the limits of the bounding box of the shape and icon combination. When the Icon Size is larger than 1, the image is cut off at the limits of the bounding box.

Example: 0.5

Background Image

For the block background, you can provide a background image or select a solid color. To select a solid background color, select this parameter. To provide a background image, clear this parameter.

Note

Changing the background color using the Format tab of the Simulink Toolstrip removes the background image and enables the Use Background Color parameter.

Example: on

To use a solid background color, select the Use Background Color parameter. Then, choose a background color from the palette of standard colors, or specify a custom color.

Tip

You can also specify the Background Color in the Format tab of the Simulink Toolstrip.

To specify the color of the block text, use the Font Color parameter.

Programmatic Use

Specify the BackgroundColor parameter for the block as a 1-by-3 [r g b] vector with values between 0 and 1 that is formatted as a string or a character vector.

Block Parameter: BackgroundColor
Type: string | character vector
Values: [r g b] vector

Specify the block background opacity as a scalar value from 0 to 1.

Example: 0.5

Specify the corner radius of the area covered by the block background color as a ratio of half of the smaller of the two block dimensions, width or height.

Example: 0.25

Foreground Image

Specify the horizontal offset of the left edge of the image from the left edge of the block as a ratio of the block width. Relative to the position of the image when the offset is 0, an offset with a negative value moves the image left, and an offset with a positive value moves the image right.

Example: 1

Specify the vertical offset of the top edge of the image from the top edge of the block as a ratio of the block height. Relative to the position of the image when the offset is 0, an offset with a negative value moves the image up, and a positive value moves the image down.

Example: 1

Specify the width of the foreground image as a ratio of the block width.

Example: 0.5

Specify the height of the foreground image as a ratio of the block height.

Example: 0.5

Select this parameter to maintain the aspect ratio when resizing the image using the Property Inspector.

Block Characteristics

Data Types

Boolean | double | enumerated | fixed point | half | integer | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

Version History

Introduced in R2021b

expand all