pimoroni-pico/micropython/modules_py/gfx_pack.md

91 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

2022-11-08 11:10:51 +00:00
# Pico GFX Pack (MicroPython) <!-- omit in toc -->
2022-11-04 17:23:30 +00:00
2022-11-07 16:11:05 +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.
2022-11-04 17:23:30 +00:00
## Table of Content
- [Table of Content](#table-of-content)
2022-11-07 12:50:50 +00:00
- [GFX Pack Class](#gfx-pack-class)
2022-11-04 17:23:30 +00:00
- [Switches](#switches)
2022-11-07 14:23:20 +00:00
- [RGBW Backlight](#rgbw-backlight)
- [Display](#display)
- [Backlight](#backlight)
2022-11-04 17:23:30 +00:00
## GFX Pack Class
2022-11-07 16:11:05 +00:00
The `GfxPack` class deals with RGBW backlight and buttons on the GFX Pack. To create one, import the `gfx_pack` module, then define a new `board` variable:
2022-11-04 17:23:30 +00:00
```python
import gfx_pack
board = gfx_pack.GfxPack()
```
2022-11-07 14:23:20 +00:00
From here, all features can be accessed by calling functions on `board`. In addition, when using Qwiic / Stemma QT devices, the I2C channel to use can be accessed with `board.i2c`.
2022-11-04 17:23:30 +00:00
### Switches
2022-11-07 14:23:20 +00:00
GFX Pack has five switches just below the display. To read one of the switches, call `.switch_pressed(switch)`, where `switch` is a value from `0` to `.NUM_SWITCHES - 1`. This returns `True` when the specified switch is pressed, and `False` otherwise.
2022-11-04 17:23:30 +00:00
2022-11-07 14:23:20 +00:00
To read a specific input, the `gfx_pack` module contains these handy constants:
2022-11-04 17:23:30 +00:00
2022-11-07 14:23:20 +00:00
* `SWITCH_A` = `0`
* `SWITCH_B` = `1`
* `SWITCH_C` = `2`
* `SWITCH_D` = `3`
* `SWITCH_E` = `4`
2022-11-04 17:23:30 +00:00
```python
2022-11-07 14:23:20 +00:00
if board.switch_pressed(SWITCH_A):
# Do something interesting here!
2022-11-04 17:23:30 +00:00
2022-11-07 14:23:20 +00:00
if board.switch_pressed(SWITCH_B):
# Do something else even more interesting here!
2022-11-04 17:23:30 +00:00
```
2022-11-07 14:23:20 +00:00
### RGBW Backlight
2022-11-04 17:23:30 +00:00
The GFX has an RGB backlight as well as the regular Matrix display backlight to change the colour of the backlight. This is accessed via the following method.
2022-11-07 14:23:20 +00:00
`.set_backlight(r, g, b, w=None)`
2022-11-04 17:23:30 +00:00
2022-11-07 14:23:20 +00:00
Where r, g, b and w are values between 0 and 255
2022-11-04 17:23:30 +00:00
example:
2022-11-07 14:23:20 +00:00
```python
board.set_backlight(255, 0, 0) # Makes the Backlight Red
board.set_backlight(0, 255, 0) # Makes the Backlight Blue
board.set_backlight(0, 0, 255) # Makes the Backlight Green
board.set_backlight(0, 0, 0, 255) # Makes the Backlight White
```
## Display
The display is all handled by our custom picographics drivers the can be accessed via `.display`.
example:
2022-11-04 17:23:30 +00:00
```python
2022-11-07 16:11:05 +00:00
display = board.display
2022-11-07 14:23:20 +00:00
display.text("Hello World!", 0, 0)
display.line(0, 0, 128, 64)
display.update() # Update display with the above items
```
All the picographics functions can be found [Here](../modules/picographics/README.md)
2022-11-04 17:23:30 +00:00
2022-11-07 14:23:20 +00:00
### Backlight
2022-11-04 17:23:30 +00:00
2022-11-07 14:23:20 +00:00
Included in the picographics display drivers is a function for controling the displays white backlight only which is accessed via `.set_backlight()`.
2022-11-04 17:23:30 +00:00
2022-11-07 16:11:05 +00:00
This function takes a floating point value between `0.0` and `1.0`
2022-11-04 17:23:30 +00:00
2022-11-07 14:23:20 +00:00
```python
2022-11-07 16:11:05 +00:00
display = board.display
2022-11-07 14:23:20 +00:00
display.set_backlight(0.0) # Backlight is off
display.set_backlight(0.5) # Backlight is 50%
display.set_backlight(1.0) # Backlight is 100%
2022-11-04 17:23:30 +00:00
```