pimoroni-pico/libraries/gfx_pack/README.md

88 wiersze
3.0 KiB
Markdown
Czysty Zwykły widok Historia

2022-11-08 11:10:51 +00:00
# Pico GFX Pack (C++) <!-- omit in toc -->
2022-11-08 11:10:51 +00:00
This library offers convenient functions for interacting with [Pico GFX Pack](https://shop.pimoroni.com/products/gfxpack) - The Pico GFX Pack adds a 128x64 LCD Matrix display to your headered Raspberry Pi Pico or PicoW, with RGBW backlight and 5 input buttons for all your display and control needs.
- [Example Program](#example-program)
- [Function Reference](#function-reference)
- [PicoGraphics](#picographics)
- [ST7789](#st7789)
## Example Program
2022-11-07 18:07:48 +00:00
The following example sets up Pico Display, displays some basic demo text and graphics and will illuminate the backlight green if the A button is pressed.
```c++
2022-11-08 11:10:51 +00:00
#include "gfx_pack.hpp"
2022-11-07 18:07:48 +00:00
#include "drivers/st7567/st7576.hpp"
#include "libraries/pico_graphics/pico_graphics.hpp"
#include "rgbled.hpp"
#include "button.hpp"
// Display driver
2022-11-07 18:07:48 +00:00
ST7567 st7567(128, 64, GfxPack::gfx_pack_pins);
2022-11-07 18:07:48 +00:00
// Graphics library - in 1 Bit mode you get 16 shades with dithering.
PicoGraphics_Pen1Bit graphics(st7567.width, st7567.height, nullptr);
2022-11-07 18:07:48 +00:00
// RGB backlight elements
RGBLED backlight_rgb(GfxPack::BL_R, GfxPack::BL_G, GfxPack::BL_B, Polarity::ACTIVE_HIGH);
// And each button
2022-11-07 18:07:48 +00:00
Button button_a(GfxPack::A);
Button button_b(GfxPack::B);
Button button_c(GfxPack::C);
Button button_d(GfxPack::D);
Button button_e(GfxPack::E);
// RGB LED
2022-11-08 11:10:51 +00:00
RGBLED led(GfxPack::LED_R, GfxPack::LED_G, GfxPack::LED_B);
int main() {
// set the backlight to a value between 0 and 255
2022-11-07 18:07:48 +00:00
// This controls the white elements of the RGBW backlight
st7567.set_backlight(100);
while(true) {
2022-11-07 18:07:48 +00:00
// detect if the A button is pressed (could be A, B, C, D or E)
if(button_a.raw(display.A)) {
2022-11-07 18:07:48 +00:00
// make the LCD glow green
// parameters are red, green, blue all between 0 and 255
// these are also gamma corrected
2022-11-07 18:07:48 +00:00
backlight_rgb.set_rgb(0, 255, 0);
}
// set the colour of the pen
// parameters are red, green, blue all between 0 and 255
graphics.set_pen(30, 40, 50);
// fill the screen with the current pen colour
graphics.clear();
// draw a box to put some text in
graphics.set_pen(10, 20, 30);
Rect text_rect(10, 10, 150, 150);
graphics.rectangle(text_rect);
// write some text inside the box with 10 pixels of margin
// automatically word wrapping
text_rect.deflate(10);
graphics.set_pen(110, 120, 130);
graphics.text("This is a message", Point(text_rect.x, text_rect.y), text_rect.w);
// now we've done our drawing let's update the screen
2022-11-07 18:07:48 +00:00
st7567.update(&graphics);
}
}
```
## Function Reference
### PicoGraphics
2022-11-07 18:07:48 +00:00
Pico GFX Pack 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-11-07 18:07:48 +00:00
### ST7567
2022-11-07 18:07:48 +00:00
Pico Display uses the ST7567 display driver to handle the LCD. For more information [read the ST7567 README.](../../drivers/st7789/README.md).