2021-06-17 15:33:05 +01:00
# Pico Display 2.0" Pack <!-- omit in toc -->
Our Pico Display Pack offers a vibrant 1.14" (240x135) IPS LCD screen for your Raspberry Pi Pico it also includes four switches and and an RGB LED!
- [Example Program ](#example-program )
- [Function Reference ](#function-reference )
- [PicoGraphics ](#picographics )
2022-06-13 14:43:08 +01:00
- [ST7789 ](#st7789 )
2021-06-17 15:33:05 +01:00
## Example Program
The following example sets up Pico Display, displays some basic demo text and graphics and will illuminate the RGB LED green if the A button is pressed.
```c++
#include "pico_display_2.hpp"
2022-06-13 14:43:08 +01:00
#include "drivers/st7789/st7789.hpp"
#include "libraries/pico_graphics/pico_graphics.hpp"
#include "rgbled.hpp"
#include "button.hpp"
// Display driver
ST7789 st7789(PicoDisplay2::WIDTH, PicoDisplay2::HEIGHT, ROTATE_0, false, get_spi_pins(BG_SPI_FRONT));
2021-06-17 15:33:05 +01:00
2022-06-13 14:43:08 +01:00
// Graphics library - in RGB332 mode you get 256 colours and optional dithering for 75K RAM.
PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr);
2021-06-17 15:33:05 +01:00
2022-06-13 14:43:08 +01:00
// RGB LED
RGBLED led(PicoDisplay2::LED_R, PicoDisplay2::LED_G, PicoDisplay2::LED_B);
// And each button
Button button_a(PicoDisplay2::A);
Button button_b(PicoDisplay2::B);
Button button_x(PicoDisplay2::X);
Button button_y(PicoDisplay2::Y);
2021-06-17 15:33:05 +01:00
int main() {
// set the backlight to a value between 0 and 255
// the backlight is driven via PWM and is gamma corrected by our
// library to give a gorgeous linear brightness range.
2022-06-13 14:43:08 +01:00
st7789.set_backlight(100);
2021-06-17 15:33:05 +01:00
while(true) {
// detect if the A button is pressed (could be A, B, X, or Y)
2022-06-13 14:43:08 +01:00
if(button_a.raw(display.A)) {
2021-06-17 15:33:05 +01:00
// make the led glow green
// parameters are red, green, blue all between 0 and 255
// these are also gamma corrected
2022-06-13 14:43:08 +01:00
led.set_rgb(0, 255, 0);
2021-06-17 15:33:05 +01:00
}
// set the colour of the pen
// parameters are red, green, blue all between 0 and 255
2022-06-13 14:43:08 +01:00
graphics.set_pen(30, 40, 50);
2021-06-17 15:33:05 +01:00
// fill the screen with the current pen colour
2022-06-13 14:43:08 +01:00
graphics.clear();
2021-06-17 15:33:05 +01:00
// draw a box to put some text in
2022-06-13 14:43:08 +01:00
graphics.set_pen(10, 20, 30);
2021-06-17 15:33:05 +01:00
Rect text_rect(10, 10, 150, 150);
2022-06-13 14:43:08 +01:00
graphics.rectangle(text_rect);
2021-06-17 15:33:05 +01:00
// write some text inside the box with 10 pixels of margin
// automatically word wrapping
text_rect.deflate(10);
2022-06-13 14:43:08 +01:00
graphics.set_pen(110, 120, 130);
graphics.text("This is a message", Point(text_rect.x, text_rect.y), text_rect.w);
2021-06-17 15:33:05 +01:00
// now we've done our drawing let's update the screen
2022-06-13 14:43:08 +01:00
st7789.update(&graphics);
2021-06-17 15:33:05 +01:00
}
}
```
## Function Reference
### PicoGraphics
Pico Display uses our Pico Graphics library to draw graphics and text. For more information [read the Pico Graphics function reference. ](../pico_graphics/README.md#function-reference ).
2022-06-13 14:43:08 +01:00
### ST7789
2021-06-17 15:33:05 +01:00
2022-06-13 14:43:08 +01:00
Pico Display uses the ST7789 display driver to handle the LCD. For more information [read the ST7789 README. ](../../drivers/st7789/README.md ).