LED

LED

A representation of a colored LED. It can be set to lit or unlit and be set to blink at any rate. The color of the LED can be set to any valid CSS color. It also has a text label.

Constructor

# new LED(parent, x, y, label, color, lit)

Constructor
Parameters:
Name Type Description
parent HTMLElement The element to add this LED to.
x number The x position of the LED. Default 0.
y number The y position of the LED. Default 0.
label string The text of the label of the LED. Default empty string.
color string The color of the LED. Default #f00.
lit boolean The initial lit state of the LED. Default false.
Source:
Example
const panel = new Panel(document.body, 20, 20, 240, 240);
const canvas = new LED(panel, 20, 20, "LED", "#f00", true);

Extends

Classes

LED

Members

# (static) color

Default color of all LEDs.
Source:

# (static) labelPosition

Default labelPosition of all LEDs.
Source:

# (static) size

Default size of all LEDs.
Source:

# color

Gets whether or not the LED is blinking. get blinking() { return this.getBlinking(); } /** Gets and sets the color of the LED.
Source:

# enabled

Sets and gets whether or not this component is enabled. Non-enabled components will be faded out and not respond to events.
Overrides:

# height

Sets and gets the height of this component.
Overrides:

# label

Gets and sets the text of the LED's text label.
Source:

# labelPosition

Gets and sets the position of the text label displayed on the LED. Valid values are "top" (default), "left", "right" and "bottom".
Source:

# lit

Gets and sets whether or not this LED is lit.
Source:

# width

Sets and gets the width of this component.
Overrides:

# x

Sets and gets the x position of this component.
Overrides:

# y

Sets and gets the y position of this component.
Overrides:

Methods

Starts the LED blinking at a specified or default rate.
Parameters:
Name Type Description
bps number Blinks per second. Defaults to 2 blinks per second if no parameter is given.
Source:
Returns:
This instance, suitable for chaining.

# getBlinking()

Source:
Returns:
whether or not the LED is blinking.

# getColor()

Source:
Returns:
the color of the LED.

# getEnabled()

Gets whether the component is enabled.
Returns:
Whether or not the component is enabled.

# getHeight()

Gets the height of the component.
Overrides:
Returns:
The height of the component.

# getLabel()

Source:
Returns:
the text in the label.

# getLabelPosition()

Source:
Returns:
the label position (top, left, right or bottom).

# getLit()

Source:
Returns:
whether or not the LED is lit.

# getWidth()

Gets the width of the component.
Overrides:
Returns:
The width of the component.

# getX()

Gets the x position of the component.
Overrides:
Returns:
The x position of the component.

# getY()

Gets the y position of the component.
Overrides:
Returns:
The y position of the component.

# move(x, y)

Moves the component to a specified position.
Parameters:
Name Type Description
x number The new x position of the component.
y number The new y position of the component.
Overrides:
Returns:
This instance, suitable for chaining.

# rotate(rad)

Rotates the component.
Parameters:
Name Type Description
rad number The number of radians to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# rotateDeg(deg)

Rotates the component.
Parameters:
Name Type Description
deg number The number of degrees to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# setColor(color)

Sets the color of this LED.
Parameters:
Name Type Description
color string The color to set.
Source:
Returns:
This instance, suitable for chaining.

# setEnabled(enabled)

Sets the enabled state of this component.
Parameters:
Name Type Description
enabled boolean Whether or not the component will be enabled.
Returns:
This instance, suitable for chaining.

# setHeight(height)

Sets the height of this component.
Parameters:
Name Type Description
height number The height of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setLabel(label)

Sets the label of this LED.
Parameters:
Name Type Description
label string The label to set on this LED.
Source:
Returns:
this instance, suitable for chaining.

# setLabelPosition(position)

Sets the text position of the text label.
Parameters:
Name Type Description
position string The position to place the text lable: "top" (default), "left", "right" or "bottom".
Source:
Returns:
this instance, suitable for chaining.

# setLit(lit)

Sets whether this LED is lit up.
Parameters:
Name Type Description
lit boolean Whether or not the LED is lit.
Source:
Returns:
This instance, suitable for chaining.

# setSize(width, height)

Sets the size of the LED. Because an LED will always be round, if you try to set width and height to different values, they will be set to the smallest value of the two.
Parameters:
Name Type Description
width number The width of the LED.
height number The height of the LED.
Overrides:
Source:
Returns:
This instance, suitable for chaining.

# setWidth(width)

Sets the width of this component.
Parameters:
Name Type Description
width number The width of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setX(x)

Sets the x position of this component.
Parameters:
Name Type Description
x number The x position of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setY(y)

Sets the y position of this component.
Parameters:
Name Type Description
y number The y position of this component.
Overrides:
Returns:
this instance, suitable for chaining.

# stop()

Stops the LED blinking and turns it off.
Source:
Returns:
This instance, suitable for chaining.