Documentation (#5)

* Add Pico Display README
* Add PicoGraphics README
* Add Pico Explorer README
* Pico Display Python README
* Add Pico Unicorn demo.py
* Add Pico Unicorn MicroPython docs
* Add Pico Unicorn C++ README
* Add Pico RGB Keypad README
driver-ltr559
Philip Howard 2021-01-27 09:36:08 +00:00 zatwierdzone przez GitHub
rodzic b3b8551af2
commit 2a7f8f4781
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 1079 dodań i 37 usunięć

Wyświetl plik

@ -1,55 +1,122 @@
# Pico Display Pack
# Pico Display 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!
Working with it is very straightforward, we've included helper functions to handle every aspect of drawing to the screen and interfacing with the other hardware.
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.
A very basic example program can be as simple as:
- [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)
## 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.hpp"
#include "pico_display.hpp"
using namespace pimoroni;
using namespace pimoroni;
uint16_t buffer[PicoDisplay::WIDTH * PicoDisplay::HEIGHT];
PicoDisplay pico_display(buffer);
uint16_t buffer[PicoDisplay::WIDTH * PicoDisplay::HEIGHT];
PicoDisplay pico_display(buffer);
int main() {
pico_display.init();
int main() {
pico_display.init();
// 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.
pico_display.set_backlight(100);
// 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.
pico_display.set_backlight(100);
while(true) {
// detect if the A button is pressed (could be A, B, X, or Y)
if(pico_display.is_pressed(pico_display.A)) {
// make the led glow green
// parameters are red, green, blue all between 0 and 255
// these are also gamma corrected
pico_display.set_led(0, 255, 0);
}
// set the colour of the pen
while(true) {
// detect if the A button is pressed (could be A, B, X, or Y)
if(pico_display.is_pressed(pico_display.A)) {
// make the led glow green
// parameters are red, green, blue all between 0 and 255
pico_display.set_pen(30, 40, 50);
// fill the screen with the current pen colour
pico_display.clear();
// draw a box to put some text in
pico_display.set_pen(10, 20, 30);
rect text_rect(10, 10, 150, 150);
pico_display.rectangle(text_rect);
// write some text inside the box with 10 pixels of margin
// automatically word wrapping
text_rect.deflate(10);
pico_display.text("This is a message", point(text_rect.x, text_rect.y), text_rect.w);
// these are also gamma corrected
pico_display.set_led(0, 255, 0);
}
// set the colour of the pen
// parameters are red, green, blue all between 0 and 255
pico_display.set_pen(30, 40, 50);
// fill the screen with the current pen colour
pico_display.clear();
// draw a box to put some text in
pico_display.set_pen(10, 20, 30);
rect text_rect(10, 10, 150, 150);
pico_display.rectangle(text_rect);
// write some text inside the box with 10 pixels of margin
// automatically word wrapping
text_rect.deflate(10);
pico_display.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
pico_display.update();
}
}
```
## 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).
### init
Sets up Pico Display. `init` must be called before any other functions since it configures the required PWM and GPIO:
```c++
pico_display.init();
```
### set_backlight
Set the display backlight from 0-255.
```c++
pico_display.set_backlight(brightness);
```
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."
### set_led
Sets the RGB LED on Pico Display with an RGB triplet:
```c++
pico_display.set_led(r, g, b);
```
Uses hardware PWM to drive the LED. Values are automatically gamma-corrected to provide smooth brightness transitions and low values may map as "off."
### is_pressed
Reads the GPIO pin connected to one of Pico Display's buttons, returning a `bool` - `true` if it's pressed and `false` if it is released.
```c++
pico_display.is_pressed(button);
```
The button vaule should be a `uint8_t` denoting a pin, and constants `A`, `B`, `X` and `Y` are supplied to make it easier. e:
```c++
bool is_a_button_pressed = pico_display.is_pressed(PicoDisplay::A)
```
### update
To display your changes on Pico Display's screen you need to call `update`:
```c++
pico_display.update();
```

Wyświetl plik

@ -0,0 +1,205 @@
# Pico Explorer Pack <!-- omit in toc -->
Our Pico Explorer Pack offers a vibrant 1.14" (240x240) IPS LCD screen for your Raspberry Pi Pico it also includes four switches, a piezo and a DRV8833 motor driver.
We've included helper functions to handle every aspect of drawing to the screen and interfacing with the buttons, piezo and motor driver. [See the library reference](#reference) for details.
- [Example Program](#example-program)
- [Reference](#reference)
- [PicoGraphics](#picographics)
- [Constants](#constants)
- [Buttons](#buttons)
- [ADC Channels](#adc-channels)
- [GPIO](#gpio)
- [Functions](#functions)
- [init](#init)
- [set_backlight](#set_backlight)
- [set_motor](#set_motor)
- [get_adc](#get_adc)
- [set_audio_pin](#set_audio_pin)
- [set_tone](#set_tone)
- [is_pressed](#is_pressed)
- [update](#update)
## Example Program
The following example sets up Pico Explorer, displays some basic demo text and graphics and will illuminate the RGB LED green if the A button is pressed.
```c++
#include "pico_explorer.hpp"
using namespace pimoroni;
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT];
PicoExplorer pico_explorer(buffer);
int main() {
pico_explorer.init();
// 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.
pico_explorer.set_backlight(100);
while(true) {
// now we've done our drawing let's update the screen
pico_explorer.update();
}
}
```
## Reference
### PicoGraphics
Pico Explorer 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).
### Constants
#### Buttons
The four buttons, A, B, X and Y have correponding constants set to their respective GPIO pins. For example:
```c++
bool a_is_pressed = pico_explorer.is_pressed(pico_explorer.A);
```
#### ADC Channels
The three ADC channels are defined as `ADC0`, `ADC1` and `ADC2`, and should be used with `get_adc`, eg:
```c++
float adc0_reading = pico_explorer.get_adc(pico_explorer.ADC0);
```
#### GPIO
The 8 general purpose IO pins on the lower Pico Explorer are GP0 through GP7, we've created constants for you to identify them easily. You should use Pico SDK's `gpio_get` to read a pin, eg:
```c++
bool pin_state = gpio_get(pico_explorer.GP0);
```
### Functions
#### init
Sets up Pico Explorer. `init` must be called before any other functions since it configures the required PWM and GPIO:
```c++
pico_explorer.init();
```
#### set_backlight
```c++
void set_backlight(uint8_t brightness);
```
Set the display backlight from 0-255.
```c++
uint8_t brightness = 128;
pico_explorer.set_backlight(brightness);
```
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."
#### set_motor
```c++
void PicoExplorer::set_motor(uint8_t channel, uint8_t action, float speed);
```
Motors are driven by PWM via an onboard DRV8833, `set_motor` will set the PWM values for the corresponding channel.
Channel should be one of `MOTOR1` or `MOTOR2`.
Action should be `FORWARD`, `REVERSE` or `STOP`.
Speed should be given as a float between `0.0` and `1.0`, eg:
```c++
pico_explorer.set_motor(pico_explorer.MOTOR1, pico_explorer.FORWARD, 0.5f);
pico_explorer.set_motor(pico_explorer.MOTOR2, pico_explorer.REVERSE, 0.5f);
```
And to stop the motor:
```c++
pico_explorer.set_motor(pico_explorer.MOTOR1, pico_explorer.STOP);
pico_explorer.set_motor(pico_explorer.MOTOR2, pico_explorer.STOP);
```
#### get_adc
```c++
float get_adc(uint8_t channel);
```
Pico Explorer's ADC channels are connected to Pico's ADC-capable pins 26, 27 and 28 which correspond to channels 0, 1 and 2 respectively. eg:
```c++
float reading = pico_explorer.get_adc(pico_explorer.ADC0);
```
Will perform a 12-bit ADC read and return the result as a float scaled from `0.0f` to `1.0f`. This value can be plugged directly into a motor, eg:
```c++
float reading = pico_explorer.get_adc(pico_explorer.ADC0);
pico_explorer.set_motor(pico_explorer.MOTOR1, pico_explorer.FORWARD, reading);
```
#### set_audio_pin
```c++
void set_audio_pin(uint8_t p);
```
`set_audio_pin` configures the PIN that Pico Explorer uses for audio output. It should be one of `GP0` through `GP7`, eg:
```c++
pico_explorer.set_audio_pin(pico_explorer.GP0);
```
Note: You must bridge this pin over to the `AUDIO` pin on the Pico Explorer header in order to drive the onboard Piezo, eg:
#### set_tone
```c++
void set_tone(uint16_t frequency, float duty = 0.2f);
```
`set_tone` will play an audio tone out of your chosen audio pin, if you have bridged that pin to "AUDIO" on the Pico Explorer header then it will sound the onboard Piezo.
```c++
uint16_t frequency = 440;
pico_explorer.set_tone(frequency);
```
#### is_pressed
```c++
bool is_pressed(uint8_t button);
```
Reads the GPIO pin connected to one of Pico Explorer's buttons, returning a `bool` - `true` if it's pressed and `false` if it is released.
```c++
pico_explorer.is_pressed(button);
```
The button vaule should be a `uint8_t` denoting a pin, and constants `A`, `B`, `X` and `Y` are supplied to make it easier. e:
```c++
bool is_a_button_pressed = pico_explorer.is_pressed(PicoDisplay::A)
```
#### update
To display your changes on Pico Explorer's screen you need to call `update`:
```c++
pico_explorer.update();
```

Wyświetl plik

@ -0,0 +1,238 @@
# Pico Graphics <!-- omit in toc -->
Pico Graphics is a tiny graphics library for 16-bit RGB565 displays.
It supports drawing text, primitive and individual pixels and includes basic types such as `rect` and `point` brimming with methods to help you develop games and applications.
- [Function Reference](#function-reference)
- [Types](#types)
- [rect](#rect)
- [rect.empty](#rectempty)
- [rect.contains](#rectcontains)
- [rect.intersects](#rectintersects)
- [rect.intersection](#rectintersection)
- [rect.inflate & rect.deflate](#rectinflate--rectdeflate)
- [point](#point)
- [point.clamp](#pointclamp)
- [operators](#operators)
- [Pens & Clipping](#pens--clipping)
- [set_pen](#set_pen)
- [create_pen](#create_pen)
- [set_clip & remove_clip](#set_clip--remove_clip)
- [Pixels](#pixels)
- [pixel](#pixel)
- [pixel_span](#pixel_span)
- [Primitives](#primitives)
- [rectangle](#rectangle)
- [circle](#circle)
- [Text](#text)
## Function Reference
### Types
#### rect
The `rect` type describes a rectangle in terms of its x, y position, width and height.
##### rect.empty
```c++
bool rect::empty();
```
##### rect.contains
```c++
bool rect::contains(const rect &p);
```
`contains` allows you to check if a `rect` contains a specific `point`. This can be useful for checking collissions (have I clicked on something?):
```c++
point cursor(50, 50);
rect widget(0, 0, 100, 100);
bool hover = widet.contains(cursor);
```
##### rect.intersects
```c++
bool rect::intersects(const rect &r);
```
`intersects` allows you to check if a `rect` intersects or overlaps another `rect`, for example these rectangles do not intersect:
```c++
rect a(10, 10, 10, 10);
rect b(30, 10, 10, 10);
a.intersects(b) == false
```
And these do:
```c++
rect a(10, 10, 10, 10);
rect b(15, 10, 10, 10);
a.intersects(b) == true
```
##### rect.intersection
```c++
rect rect::intersection(const rect &r);
```
`intersection` takes an input `rect` and returns a new `rect` that describes the region in which the two `rect`s overlap. For example:
```c++
rect a(0, 0, 10, 20);
rect b(0, 0, 20, 10);
rect c = a.intersection(b);
```
In this case `c` would equal `rect c(0, 0, 10, 10);` since this is the region that `a` and `b` overlap.
##### rect.inflate & rect.deflate
```c++
void rect::inflate(int32_t v);
void rect::declate(int32_t v);
```
`inflate` will inflate a `rect`, like a balooon, by adding the number of pixels you specify to all sides. For example:
```c++
rect box(10, 10, 10, 10);
box.inflate(10);
```
Would inflate our `box` to start at 0,0 and be 30x30 pixels in size.
`deflate` does the opposite:
```c++
rect box(10, 10, 10, 10);
box.deflate(1);
```
Would deflate our `box` to start at `11,11` and be 8x8 pixels in size.
Since `rectangle` *always* draws a filled rectangle, this can be useful to add an outline of your desired thickness:
```c++
rect box(10, 10, 100, 100);
box.inflate(1); // Inflate our box by 1px on all sides
screen.set_pen(255, 255, 255); // White outline
screen.rectangle(box);
box.deflate(1); // Return to our original box size
screen.set_pen(0, 0, 0); /// Black fill
screen.rectangle(box);
```
#### point
The `point` type descrives a single point - synonymous with a pixel - in terms of its x and y position.
##### point.clamp
```c++
point point::clamp(const rect &r);
```
A point can be clamped within the confines of a `rect`. This is useful for keeping - for example - a cursor within the bounds of the screen:
```c++
point cursor(10, 1000); // A point, far outside the bounds of our screen
cursor.clamp(screen.bounds)); // Clamp to the screen
```
##### operators
TODO
### Pens & Clipping
#### set_pen
In order to draw anything with Pico Graphics you must first set the pen to your desired colour, there are two ways to do this:
```c++
void PicoGraphics::set_pen(uint8_t r, uint8_t g, uint8_t b);
void PicoGraphics::set_pen(uint16_t p);
```
The former uses 8-bit R, G and B values which are clipped to 5, 6 and 5 bits respectively to form a 16-bit colour. Internally it uses `create_pen`.
The latter takes a 16-bit colour directly and is a great way to save a few cycles if you're working with a constant palette of colours.
#### create_pen
```c++
uint16_t PicoGraphics::create_pen(uint8_t r, uint8_t g, uint8_t b);
```
Create pen takes R, G and B values, clamps them to 5, 6 and 5 bits respectively and joins them into a `uint16_t` pen that represents a single 16-bit colour.
Creating your pens up front and storing them as `uint16_t` can speed up switching colours.
#### set_clip & remove_clip
```c++
void PicoGraphics::set_clip(const rect &r);
void PicoGraphics::remove_clip();
```
`set_clip` applies a clipping rectangle to the drawing surface. Any pixels outside of this rectangle will not be drawn. By default drawing operations are clipped to `bounds` since it's impossible to draw outside of the buffer.
`remove_clip` sets the surface clipping rectangle back to the surface `bounds`.
### Pixels
#### pixel
```c++
void PicoGraphics::pixel(const point &p);
```
`pixel` sets the pixel at `point p` to the current `pen`.
#### pixel_span
```c++
void PicoGraphics::pixel_span(const point &p, int32_t l)
```
`pixel_span` draws a horizontal line of pixels of length `int32_t l` starting at `point p`.
### Primitives
#### rectangle
```c++
void PicoGraphics::rectangle(const rect &r) ;
```
`rectangle` draws a filled rectangle described by `rect`.
#### circle
```c++
PicoGraphics::circle(const point &p, int32_t radius)
```
`circle` draws a filled circle centered on `point p` with radius `int32_t radius`.
### Text
```c++
void PicoGraphics::text(const std::string &t, const point &p, int32_t wrap, uint8_t scale);
```
`text` allows you to draw a string at `point p`, with a maximum line-width of `int32_t wrap`.
The 6x6 pixel font characters are encoded in `font_data.cpp` along with their character widths so that text can be drawn variable-width.
You can scale text with `uint8_t scale` for 12x12, 18x18, etc character sizes.

Wyświetl plik

@ -0,0 +1,171 @@
# Pico RGB Keypad Pack <!-- omit in toc -->
Our Pico Keypad Pack offers a 4x4, squishy, RGB illuminated keypad for the Raspberry Pi Pico. The buttons are read via an i2c IO expander and the LEDs are APA102s driven by SPI.
We've included helper functions to handle every aspect of setting beautiful RGB colours and interfacing with the squishy buttons. [See the library reference](#reference) for details.
- [Example Program](#example-program)
- [Reference](#reference)
- [Constants](#constants)
- [Dimensions](#dimensions)
- [Functions](#functions)
- [set_brightness](#set_brightness)
- [illuminate](#illuminate)
- [clear](#clear)
- [get_button_states](#get_button_states)
- [update](#update)
## Example Program
The following example sets up Pico RGB Keypad and toggles the key LEDs on/off when they are pressed.
```c++
#include "pico_rgb_keypad.hpp"
using namespace pimoroni;
PicoRGBKeypad pico_rgb_keypad;
uint16_t last_buttons = 0;
uint16_t led_states = 0;
int main() {
pico_rgb_keypad.init(); // Set up GPIO
pico_rgb_keypad.set_brightness(0.1f); // It's bright, trust us!
while(true) {
current_buttons = get_button_states();
changed_buttons = current_buttons ^ last_buttons;
pressed_buttons = current_buttons & changed;
released_buttons = last_buttons & changed;
// Toggle the LED states when a button is pressed
led_states ^= pressed_buttons;
// Grab each bit from led_states and update the
// corresponding LED
for(auto i = 0u; i < pico_rgb_keypad.NUM_KEYS; i++) {
bool state = led_states & (1 << i);
if(state) {
pico_rgb_keypad.illuminate(i, 0xaa, 0x33, 0xff);
} else {
pico_rgb_keypad.illuminate(i, 0x00, 0x00, 0x00);
}
}
last_buttons = current_buttons;
pico_rgb_keypad.update();
sleep_ms(100);
}
}
```
## Reference
### Constants
#### Dimensions
Pico RGB Keypad includes the constants `WIDTH`, `HEIGHT` and `NUM_PAD` (width * height) so you can avoid these creeping in as magic numbers in your code.
For example, you might iterate through all pads like so:
```c++
for(auto y = 0u; y < pico_rgb_keypad.HEIGHT; y++) {
for(auto x = 0u; x < pico_rgb_keypad.WIDTH; x++) {
pico_rgb_keypad.illuminate(x, y, 255, 0, 255);
}
}
```
### Functions
#### set_brightness
```c++
void set_brightness(float brightness);
```
Sets the 5-bit global brightness value for each LED.
#### illuminate
```c++
void illuminate(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b);
void illuminate(uint8_t i, uint8_t r, uint8_t g, uint8_t b);
```
You can specify a single keypad key by its `x,y` coordinates, eg:
```c++
pico_rgb_keypad.illuminate(x, y, 255, 0, 255);
```
Or its index, eg:
```c++
pico_rgb_keypad.illuminate(index, 255, 0, 255);
```
#### clear
```c++
void clear();
```
Clears the illumination states of all keys, setting them to `0,0,0`, this is equivilent to:
```c++
for(auto i = 0u; i < pico_rgb_keypad.NUM_PADS; i++) {
pico_rgb_keypad.illuminate(i, 0, 0, 0);
}
```
#### get_button_states
```c++
uint16_t get_button_states();
```
Reads a 16-bit integer from the i2c IO expander connected to the buttons.
The button states are not debounced, you can handle button changes by introducing a small delay between button reads, keeping the last button state and using bitwise operations to get a mask of changed buttons and, subsequently, figured out which have been pressed and/or released, eg:
```c++
current_buttons = get_button_states();
// XOR the previous and current button states.
// This gives us a mask of changes, since:
// 0 ^ 0 = 0 -- was 0, now 0, no change
// 0 ^ 1 = 1 -- was 0, now 1, changed!
// 1 ^ 0 = 1 -- was 1, now 0, changed!
// 1 ^ 1 = 0 -- was 1, now 1, no change
changed_buttons = current_buttons ^ last_buttons;
// AND the current button states with the change mask.
// This gives us all the pressed buttons, since:
// 0 & 0 = 0 -- is 0, unchanged, not pressed
// 0 & 1 = 0 -- is 0, has changed, must be released
// 1 & 0 = 0 -- is 1, unchanged, held
// 1 & 1 = 1 -- is 1, changed, pressed!
pressed_buttons = current_buttons & changed;
// AND the last button states with the change mask.
// This gives us all the released buttons, since:
// 0 & 0 = 0 -- was 0, unchanged, not released
// 0 & 1 = 0 -- was 0, changed, must be pressed
// 1 & 0 = 0 -- was 1, unchanged, held
// 1 & 1 = 1 -- was 1, changed, must be released!
released_buttons = last_buttons & changed;
last_buttons = current_buttons;
```
#### update
```c++
void update();
```
Update the RGB keypad lights with your changes.

Wyświetl plik

@ -0,0 +1,99 @@
# Pico Unicorn Pack - MicroPython <!-- omit in toc -->
Our Pico Unicorn Pack offers 7x17 bright RGB LEDs driven by Pico's PIO.
Pico Unicorn uses SM0 of PIO0.
We've included helper functions to handle every aspect of drawing to the display and interfacing with the buttons. See the [function reference](#function-reference) for details.
- [Example Program](#example-program)
- [Reference](#reference)
- [Constants](#constants)
- [Buttons](#buttons)
- [WIDTH / HEIGHT](#width--height)
- [Functions](#functions)
- [init](#init)
- [set_pixel](#set_pixel)
- [is_pressed](#is_pressed)
## Example Program
The following example sets up Pico Unicorn, displays some basic demo text and graphics and will illuminate the RGB LED green if the A button is presse
```c++
```
## Reference
### Constants
#### Buttons
The four buttons, A, B, X and Y have correponding constants set to their respective GPIO pins. For example:
```c++
bool a_is_pressed = pico_unicorn.is_pressed(pico_unicorn.A);
```
#### WIDTH / HEIGHT
The width and height of Pico Unicorn are available in constants `WIDTH` and `HEIGHT`.
For example:
```c++
int num_pixels = pico_unicorn.WIDTH * pico_unicorn.HEIGHT;
```
### Functions
#### init
Sets up Pico Unicorn. `init` must be called before any other functions since it configures the PIO and require GPIO inputs. Just call `init()` like so:
```c++
PicoUnicorn pico_unicorn;
pico_unicorn.init();
```
#### set_pixel
```c++
void set_pixel(uint8_t x, uint8_t y, uint8_t r, uint8_t g, uint8_t b);
void set_pixel(uint8_t x, uint8_t y, uint8_t v);
```
Sets an RGB LED on Pico Unicorn with an RGB triplet:
```c++
pico_unicorn.set_pixel(x, y, r, g, b);
```
Uses hardware PWM to drive the LED. Values are automatically gamma-corrected to provide smooth brightness transitions and low values may map as "off."
Alternatively you can use:
```c++
pico_unicorn.set_pixel(x, y, v);
```
Which sets the R, G and B elements of the pixel to the same value- lighting it up white at your chosen intensity.
#### is_pressed
```c++
bool is_pressed(uint8_t button);
```
Reads the GPIO pin connected to one of Pico Unicorn's buttons, returning a `bool` - `true` if it's pressed and `false` if it is released.
```c++
pico_unicorn.is_pressed(button);
```
The button vaule should be a `uint8_t` denoting a pin, and constants `A`, `B`, `X` and `Y` are supplied to make it easier. e:
```c++
bool is_a_button_pressed = pico_unicorn.is_pressed(PicoUnicorn::A)
```

Wyświetl plik

@ -0,0 +1,49 @@
import math
import time
import picounicorn
picounicorn.init()
# From CPython Lib/colorsys.py
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h*6.0)
f = (h*6.0) - i
p = v*(1.0 - s)
q = v*(1.0 - s*f)
t = v*(1.0 - s*(1.0-f))
i = i%6
if i == 0:
return v, t, p
if i == 1:
return q, v, p
if i == 2:
return p, v, t
if i == 3:
return p, q, v
if i == 4:
return t, p, v
if i == 5:
return v, p, q
w = picounicorn.get_width()
h = picounicorn.get_height()
# Display a rainbow across Pico Unicorn
for x in range(w):
for y in range(h):
r, g, b = [int(c * 255) for c in hsv_to_rgb(x / w, y / h, 1.0)]
picounicorn.set_pixel(x, y, r, g, b)
print("Press Button A")
while not picounicorn.is_pressed(picounicorn.BUTTON_A): # Wait for Button A to be pressed
pass
# Clear the display
for x in range(w):
for y in range(h):
picounicorn.set_pixel(x, y, 0, 0, 0)
print("Button A pressed!")

Wyświetl plik

@ -0,0 +1,89 @@
# Pico Display Pack - MicroPython <!-- 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!
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.
- [Example Program](#example-program)
- [Function Reference](#function-reference)
- [init](#init)
- [set_backlight](#set_backlight)
- [set_led](#set_led)
- [is_pressed](#is_pressed)
- [update](#update)
## 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 presse
```python
import picodisplay
# Initialise Picodisplay with a bytearray display buffer
buf = bytearray(picodisplay.get_width() * picodisplay.get_height() * 2)
picodisplay.init(buf)
picodisplay.set_pen(255, 0, 0) # Set a red pen
picodisplay.clear() # Clear the display buffer
picodisplay.update() # Update the display with our changes
picodisplay.set_led(255, 0, 0) # Set the RGB LED to Red
picodisplay.set_led(0, 255, 0) # Set the RGB LED to Green
picodisplay.set_led(0, 0, 255) # Set the RGB LED to Blue
while not picodisplay.is_pressed(picodisplay.BUTTON_A): # Wait for Button A to be pressed
pass
```
## Function Reference
### init
Sets up Pico Display. `init` must be called before any other functions since it configures the required PWM and GPIO. `init()` needs a bytearray type display buffer that MicroPython's garbage collection isn't going to eat, make sure you create one and pass it in like so:
```python
buf = bytearray(picodisplay.get_width() * picodisplay.get_height() * 2)
picodisplay.init(buf)
```
### set_backlight
Set the display backlight from 0.0 to 1.0
```python
picodisplay.set_backlight(brightness)
```
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."
### set_led
Sets the RGB LED on Pico Display with an RGB triplet:
```python
picodisplay.set_led(r, g, b)
```
Uses hardware PWM to drive the LED. Values are automatically gamma-corrected to provide smooth brightness transitions and low values may map as "off."
### is_pressed
Reads the GPIO pin connected to one of Pico Display's buttons, returning `True` if it's pressed and `False` if it is released.
```python
picodisplay.is_pressed(button)
```
The button vaule should be a number denoting a pin, and constants `picodisplay.BUTTON_A`, `picodisplay.BUTTON_B`, `picodisplay.BUTTON_X` and `picodisplay.BUTTON_Y` are supplied to make it easier. e:
```python
is_a_button_pressed = picodisplay.is_pressed(picodisplay.BUTTON_A)
```
### update
To display your changes on Pico Display's screen you need to call `update`:
```python
picodisplay.update()
```

Wyświetl plik

@ -0,0 +1,124 @@
# Pico Unicorn Pack - MicroPython <!-- omit in toc -->
Our Pico Unicorn Pack offers 7x17 bright RGB LEDs driven by Pico's PIO.
We've included helper functions to handle every aspect of drawing to the display and interfacing with the buttons. See the [function reference](#function-reference) for details.
- [Example Program](#example-program)
- [Function Reference](#function-reference)
- [init](#init)
- [set_pixel](#set_pixel)
- [set_pixel_value](#set_pixel_value)
- [is_pressed](#is_pressed)
- [get_width / get_height](#get_width--get_height)
## Example Program
The following example sets up Pico Unicorn, displays some basic demo text and graphics and will illuminate the RGB LED green if the A button is presse
```python
import math
import time
import picounicorn
picounicorn.init()
# From CPython Lib/colorsys.py
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h*6.0)
f = (h*6.0) - i
p = v*(1.0 - s)
q = v*(1.0 - s*f)
t = v*(1.0 - s*(1.0-f))
i = i%6
if i == 0:
return v, t, p
if i == 1:
return q, v, p
if i == 2:
return p, v, t
if i == 3:
return p, q, v
if i == 4:
return t, p, v
if i == 5:
return v, p, q
w = picounicorn.get_width()
h = picounicorn.get_height()
# Display a rainbow across Pico Unicorn
for x in range(w):
for y in range(h):
r, g, b = [int(c * 255) for c in hsv_to_rgb(x / w, y / h, 1.0)]
picounicorn.set_pixel(x, y, r, g, b)
print("Press Button A")
while not picounicorn.is_pressed(picounicorn.BUTTON_A): # Wait for Button A to be pressed
pass
# Clear the display
for x in range(w):
for y in range(h):
picounicorn.set_pixel(x, y, 0, 0, 0)
print("Button A pressed!")
```
## Function Reference
### init
Sets up Pico Unicorn. `init` must be called before any other functions since it configures the PIO and require GPIO inputs. Just call `init()` like so:
```python
picounicorn.init()
```
### set_pixel
Sets an RGB LED on Pico Unicorn with an RGB triplet:
```python
picounicorn.set_pixel(x, y, r, g, b)
```
Uses hardware PWM to drive the LED. Values are automatically gamma-corrected to provide smooth brightness transitions and low values may map as "off."
### set_pixel_value
Sets all elements of an RGB LED on Pico Unicorn to a single value:
```python
picounicorn.set_pixel_value(x, y, v)
```
This lights an LED up white at varying intensity and is useful if you want to pretend Pico Unicorn is a monochrome display.
### is_pressed
Reads the GPIO pin connected to one of Pico Unicorn's buttons, returning `True` if it's pressed and `False` if it is released.
```python
picounicorn.is_pressed(button)
```
The button vaule should be a number denoting a pin, and constants `picounicorn.BUTTON_A`, `picounicorn.BUTTON_B`, `picounicorn.BUTTON_X` and `picounicorn.BUTTON_Y` are supplied to make it easier. e:
```python
is_a_button_pressed = picounicorn.is_pressed(picounicorn.BUTTON_A)
```
### get_width / get_height
You can get the width and height of the Pico Unicorn display:
```python
width = picounicorn.get_width()
height = picounicorn.get_height()
```
This is useful where you're looping through the rows and columns to display a pattern- such as a rainbow using `hsv_to_rgb`.