pimoroni-pico/libraries/pico_unicorn
Charlie Birks 8be98da0e5
Use float pow for pico unicorn gamma
Looks like that was intended based on the float cast and all the f suffixes...
2022-05-23 14:09:50 +01:00
..
CMakeLists.txt moved examples into their own directory, moved pico support code into libraries directory, fixed cmake configuration 2021-01-16 16:00:15 +00:00
README.md Documentation (#5) 2021-01-27 09:36:08 +00:00
pico_unicorn.cmake Add cmake files for other libraries 2021-01-22 14:33:17 +00:00
pico_unicorn.cpp Use float pow for pico unicorn gamma 2022-05-23 14:09:50 +01:00
pico_unicorn.hpp Pico Unicorn: fix MP soft reset & cleanup 2021-08-26 21:58:37 +01:00
pico_unicorn.pio perform updates via repeated dma transfer instead of blocking writes to the pio fifo 2021-01-19 07:09:58 +00:00

README.md

Pico Unicorn Pack - MicroPython

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 for details.

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


Reference

Constants

Buttons

The four buttons, A, B, X and Y have correponding constants set to their respective GPIO pins. For example:

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:

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:

PicoUnicorn pico_unicorn;
pico_unicorn.init();

set_pixel

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:

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:

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

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.

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:

bool is_a_button_pressed = pico_unicorn.is_pressed(PicoUnicorn::A)