pxt-calliope/docs/reference/led/plot.md
2016-06-11 22:28:57 -04:00

1.3 KiB

Plot

Turn on a LED light on the LED screen. Specify which LED using x, y coordinates. Use unplot to turn a LED off.

led.plot(0,0);

Parameters

  • x - Number; the x coordinate or horizontal position (0, 1, 2, 3, 4)
  • y - Number; the y coordinate or vertical position (0, 1, 2, 3, 4)

If a parameter is out of bounds (a value other than 0-4), then this function will do nothing.

x, y coordinates?

The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the x, y coordinates, see LED screen.

This code turns on the centre LED:

led.plot(2, 2)

Get the LED on/off state

Use the point function to find out if a LED is on or off.

Example: a square

The following example uses a for loop and the plot function to turn on the LED lights along the edge of the screen, making a square:

for (let i = 0; i < 5; i++) {
    led.plot(0, i)
    led.plot(4, i)
    led.plot(i, 0)
    led.plot(i, 4)
    basic.pause(500)
}

See also

unplot, point, LED screen