2021-01-27 09:36:08 +00:00
# Pico Display Pack <!-- omit in toc -->
2021-01-22 08:21:14 +00:00
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!
2021-01-27 09:36:08 +00:00
We've included helper functions to handle every aspect of drawing to the screen and interfacing with the buttons and LED. See the [function reference ](#function-reference ) for details.
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
- [Example Program ](#example-program )
- [Function Reference ](#function-reference )
- [PicoGraphics ](#picographics )
- [init ](#init )
- [set_backlight ](#set_backlight )
- [set_led ](#set_led )
- [is_pressed ](#is_pressed )
- [update ](#update )
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00: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.
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
```c++
#include "pico_display.hpp"
2022-05-12 18:40:37 +01:00
#include "generic_st7789.hpp"
#include "rgbled.hpp"
#include "button.hpp"
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
uint16_t buffer[PicoDisplay::WIDTH * PicoDisplay::HEIGHT];
2022-05-12 18:40:37 +01:00
// Swap WIDTH and HEIGHT to rotate 90 degrees
ST7789Generic display(PicoDisplay::WIDTH, PicoDisplay::HEIGHT, buffer);
// Create an RGB LED
RGBLED led(PicoDisplay::LED_R, PicoDisplay::LED_G, PicoDisplay::LED_B);
// And each button
Button button_a(PicoDisplay::A);
Button button_b(PicoDisplay::B);
Button button_x(PicoDisplay::X);
Button button_y(PicoDisplay::Y);
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
int main() {
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
// 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-05-12 18:40:37 +01:00
display.set_backlight(100);
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
while(true) {
// detect if the A button is pressed (could be A, B, X, or Y)
2022-05-12 18:40:37 +01:00
if(button_a.raw(display.A)) {
2021-01-27 09:36:08 +00:00
// make the led glow green
2021-01-22 08:21:14 +00:00
// parameters are red, green, blue all between 0 and 255
2021-01-27 09:36:08 +00:00
// these are also gamma corrected
2022-05-12 18:40:37 +01:00
led.set_rgb(0, 255, 0);
2021-01-27 09:36:08 +00:00
}
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
// set the colour of the pen
// parameters are red, green, blue all between 0 and 255
2022-05-12 18:40:37 +01:00
display.set_pen(30, 40, 50);
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
// fill the screen with the current pen colour
2022-05-12 18:40:37 +01:00
display.clear();
2021-01-22 08:21:14 +00:00
2021-01-27 09:36:08 +00:00
// draw a box to put some text in
2022-05-12 18:40:37 +01:00
display.set_pen(10, 20, 30);
2021-02-09 14:01:58 +00:00
Rect text_rect(10, 10, 150, 150);
2022-05-12 18:40:37 +01:00
display.rectangle(text_rect);
2021-01-27 09:36:08 +00:00
// write some text inside the box with 10 pixels of margin
// automatically word wrapping
text_rect.deflate(10);
2022-05-12 18:40:37 +01:00
display.set_pen(110, 120, 130);
display.text("This is a message", Point(text_rect.x, text_rect.y), text_rect.w);
2021-01-22 08:21:14 +00:00
// now we've done our drawing let's update the screen
2022-05-12 18:40:37 +01:00
display.update();
2021-01-22 08:21:14 +00:00
}
2021-01-27 09:36:08 +00: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-05-12 18:40:37 +01:00
### configure_display
2021-01-27 09:36:08 +00:00
2022-05-12 18:40:37 +01:00
Configures an ST7789 display. Done by default, but you can use this to set 180 degree rotation like so:
2021-01-27 09:36:08 +00:00
```c++
2022-05-12 18:40:37 +01:00
display.configure_display(true);
2021-01-27 09:36:08 +00:00
```
2022-05-12 18:40:37 +01:00
### flip
Deprecated: calls `configure_display(true);`
2021-01-27 09:36:08 +00:00
### set_backlight
Set the display backlight from 0-255.
```c++
2022-05-12 18:40:37 +01:00
display.set_backlight(brightness);
2021-01-27 09:36:08 +00:00
```
Uses hardware PWM to dim the display backlight, dimming values are gamma-corrected to provide smooth brightness transitions across the full range of intensity. This may result in some low values mapping as "off."
### update
To display your changes on Pico Display's screen you need to call `update` :
```c++
2022-05-12 18:40:37 +01:00
display.update();
```