2016-03-26 00:47:20 +01:00
# LED screen
The micro:bit LED screen
2016-04-16 00:40:55 +02:00
```sim
2016-06-14 03:42:55 +02:00
basic.showLeds(`
# . # . #
. # . # .
# . # . #
. # . # .
# . # . #
`);
2016-04-16 00:40:55 +02:00
```
2016-03-26 00:47:20 +01:00
The micro:bit LED screen consists of 25 red LED lights arranged in a 5X5 grid (5 LEDs across by 5 LEDs down).
2016-06-14 03:58:08 +02:00
In the screen above, we created a checkerboard pattern using the LEDs.
2016-03-26 00:47:20 +01:00
### Which LED?
2016-06-14 03:58:08 +02:00
You use `(x ,y)` coordinates to specify a particular LED in the grid;
where `x` is the horizontal position (0,1,2,3,4) and `y` is the vertical position
(0, 1, 2, 3, 4).
To figure out the ``x``, ``y`` coordinates, position your micro:bit horizontally, like a credit card (see picture above).
2016-03-26 00:47:20 +01:00
Here are the x, y coordinates for the LEDs in the 5X5 grid:
2016-06-14 03:42:55 +02:00
`(0,0)` `(1,0)` `(2,0)` `(3,0)` `(4,0)`
2016-03-26 00:47:20 +01:00
2016-06-14 03:42:55 +02:00
`(0,1)` `(1,1)` `(2,1)` `(3,1)` `(4,1)`
2016-03-26 00:47:20 +01:00
2016-06-14 03:42:55 +02:00
`(0,2)` `(1,2)` `(2,2)` `(3,2)` `(4,2)`
2016-03-26 00:47:20 +01:00
2016-06-14 03:42:55 +02:00
`(0,3)` `(1,3)` `(2,3)` `(3,3)` `(4,3)`
2016-03-26 00:47:20 +01:00
2016-06-14 03:42:55 +02:00
`(0,4)` `(1,4)` `(2,4)` `(3,4)` `(4,4)`
2016-03-26 00:47:20 +01:00
2016-06-14 03:58:08 +02:00
The x, y coordinates for the LED in the centre of the grid are `(2,2)` . Starting from `(0,0)` count over 2 columns and then down 2 rows.
### Check your understanding
Which LEDs are turned on in the checkboard pattern above?
2016-03-26 00:47:20 +01:00
### Row, column - 1
2016-06-14 03:58:08 +02:00
Since the row and column numbers start at 0, an easy way to figure out the (x,y) coordinates
is to subtract 1 from the row and column number (when counting from 1).
In other words, to specify the LED in the 4th column 5th row, subtract 1 from each number to get coordinates `(3,4)` .
2016-03-26 00:47:20 +01:00
### Turn a LED on/off
2016-04-16 00:53:20 +02:00
Use [plot ](/reference/led/plot ) and [unplot ](/reference/led/unplot ) to turn a LED on or off
2016-03-26 00:47:20 +01:00
2016-04-16 00:40:55 +02:00
```blocks
2016-06-14 03:42:55 +02:00
led.plot(0,0);
2016-06-14 03:58:08 +02:00
led.plot(1,1);
basic.pause(1000);
led.unplot(0,0);
2016-06-14 03:42:55 +02:00
basic.pause(1000);
2016-06-14 03:58:08 +02:00
led.unplot(1,1);
2016-04-16 00:40:55 +02:00
```
2016-03-26 00:47:20 +01:00
### Is a LED on/off?
2016-04-16 00:53:20 +02:00
Use the [point ](/reference/led/point ) function to find out if a LED is on or off.
2016-03-26 00:47:20 +01:00
2016-04-16 00:40:55 +02:00
```blocks
if(led.point(0,0)) {
}
```
2016-03-26 00:47:20 +01:00
### Display images, strings and numbers
2016-04-16 00:02:26 +02:00
Instead of turning individual LEDs on or off, as above, you can display an [image ](/reference/images/image ) directly to the screen or show text/numbers on screen using the [show number ](/reference/basic/show-number )/[show string](/reference/basic/show-string) function.
2016-03-26 00:47:20 +01:00
### The display buffer
The micro:bit runtime keeps an in-memory representation of the state of all 25 LEDS. This state is known as the "display buffer" and controls which LEDS are on and which are off. The plot/unplot/point functions access the display buffer directly. On the other hand, the functions that show an image, number or string overwrite the buffer completely. To illustrate, first try running this code sequence
2016-04-16 00:40:55 +02:00
```blocks
basic.showString("d")
2016-03-26 00:47:20 +01:00
led.plot(0, 0)
```
You will see the letter "d" displayed as well as the LED in position `0,0` lit up. Now try reversing the order of the two statements above:
2016-04-16 00:40:55 +02:00
```blocks
2016-03-26 00:47:20 +01:00
led.plot(0, 0)
basic.showString("d", 150)
```
You will not see the LED at position `0,0` lit up because the `show string` function overwrites the whole display buffer.
2016-10-28 17:34:04 +02:00
### Pins: P3, P4, P6, P7, P9, P10
These pins are coupled to the LED matrix display, and also it’ s associated ambient light sensing mode.
To disable the display driver feature (which will automatically disable the light sensing feature) use the function [led.enable ](/reference/led/enable ).
More information at http://tech.microbit.org/hardware/edgeconnector_ds/ .