Merge branch 'main' into driver/st7567

pull/561/head
ZodiusInfuser 2022-11-08 11:17:24 +00:00 zatwierdzone przez GitHub
commit f1d9ec7c61
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
15 zmienionych plików z 691 dodań i 35 usunięć

Wyświetl plik

@ -21,7 +21,8 @@ This repository contains the C/C++ and MicroPython libraries for our range of RP
- [RP2040 Boards](#rp2040-boards)
- [Pico W Aboard](#pico-w-aboard)
- [Breakouts](#breakouts)
- [Tutorials & Guides](#tutorials--guides)
- [Kits](#kits)
- [Tutorials and Guides](#tutorials-and-guides)
# MicroPython
@ -31,7 +32,7 @@ The easiest way to get started. If you're new to Pico, we recommend you read our
New releases are issued regularly with new libraries, bug fixes to our existing libraries and new features inherited from MicroPython upstream. Be sure to check back!
* :link: [Tutorial: Getting started with Pico](https://learn.pimoroni.com/article/getting-started-with-pico)
* :link: [Learn: Getting started with Pico](https://learn.pimoroni.com/article/getting-started-with-pico)
* [Readme: Instructions for installing MicroPython](setting-up-micropython.md)
* [Readme: Frequently Asked Questions](faqs-micropython.md)
* [Pimoroni Pico MicroPython + Drivers Releases](https://github.com/pimoroni/pimoroni-pico/releases)
@ -45,9 +46,9 @@ You can find MicroPython examples for supported sensors, packs and bases in the
# C/C++
For more advanced users that want to unleash the full power of Pico, you can use our C++ libraries. If you know what you're doing and want to build your own Pimoroni Pico project then start with the [Pimoroni Pico SDK Boilerplate](https://github.com/pimoroni/pico-boilerplate).
Advanced users that want to unleash the full power of Pico can use our C++ libraries. If you know what you're doing and want to build your own Pimoroni Pico project then start with the [Pimoroni Pico SDK Boilerplate](https://github.com/pimoroni/pico-boilerplate).
* :link: [Tutorial: Pico C++ Development on Windows](https://learn.pimoroni.com/article/pico-development-using-wsl)
* :link: [Learn: Pico C++ Development on Windows](https://learn.pimoroni.com/article/pico-development-using-wsl)
* [Readme: Instructions for setting up the C/C++ SDK](setting-up-the-pico-sdk.md)
## C++ Examples
@ -98,6 +99,9 @@ We also maintain a C++/CMake boilerplate with GitHub workflows configured for te
* Automation 2040 W (inputs, outputs and relays, 6-40V compatible) - https://shop.pimoroni.com/products/automation-2040-w
* Inventor 2040 W (motors, servos, noise) - https://shop.pimoroni.com/products/inventor-2040-w
* Inky Frame 5.7" (7-colour E Ink) - https://shop.pimoroni.com/products/inky-frame-5-7
* Automation 2040 W Mini (inputs, outputs and a relay, 6-40V compatible) - https://shop.pimoroni.com/products/automation-2040-w-mini
* Plasma Stick 2040 W (bijou LED strip controller) - https://shop.pimoroni.com/products/plasma-stick-2040-w
* Galactic Unicorn (dazzling 53 x 11 LED matrix) - https://shop.pimoroni.com/products/galactic-unicorn
## Breakouts
@ -130,14 +134,20 @@ We also maintain a C++/CMake boilerplate with GitHub workflows configured for te
* SCD41 CO2 Sensor (Carbon Dioxide / Temperature / Humidity) - https://shop.pimoroni.com/products/scd41-co2-sensor-breakout
* VL53L5CX 8x8 Time of Flight Array Sensor - https://shop.pimoroni.com/products/vl53l5cx-time-of-flight-tof-sensor-breakout
## Kits
# Tutorials & Guides
* Wireless Plasma Kit (Plasma Stick + LED wire + bottle!) - https://shop.pimoroni.com/products/wireless-plasma-kit
- :link: [Getting started with (MicroPython on) Pico](https://learn.pimoroni.com/article/getting-started-with-pico)
- :link: [Pico C++ Development on Windows / WSL](https://learn.pimoroni.com/article/pico-development-using-wsl)
# Tutorials and Guides
- :link: [Getting Started with (MicroPython on) Pico](https://learn.pimoroni.com/article/getting-started-with-pico)
- :link: [Pico C/C++ Development on Windows / WSL](https://learn.pimoroni.com/article/pico-development-using-wsl)
- :link: [Getting Started with Interstate 75](https://learn.pimoroni.com/article/getting-started-with-interstate-75)
- :link: [Getting Started with Plasma 2040](https://learn.pimoroni.com/article/plasma-2040)
- :link: [Assembling Keybow 2040](https://learn.pimoroni.com/article/assembling-keybow-2040)
- :link: [Getting Started with Badger 2040](https://learn.pimoroni.com/article/getting-started-with-badger-2040)
- :link: [MicroPython and VL53L5CX](https://learn.pimoroni.com/article/micropython-and-vl53l5cx)
- :link: [Getting Started with Tufty 2040](https://learn.pimoroni.com/article/getting-started-with-tufty-2040)
- :link: [Getting Started with Inky Frame](https://learn.pimoroni.com/article/getting-started-with-inky-frame)
- :link: [Getting Started with Automation 2040 W (and Mini)](https://learn.pimoroni.com/article/getting-started-with-automation-2040-w)
- :link: [Assembling Wireless Plasma Kit](https://learn.pimoroni.com/article/assembling-wireless-plasma-kit)

Wyświetl plik

@ -1,7 +1,9 @@
# Galactic Unicorn <!-- omit in toc -->
# Galactic Unicorn (C/C++)<!-- omit in toc -->
Galactic Unicorn offers 53x11 bright RGB LEDs driven by Pico W's PIO in addition to a 1W amplifier + speaker, a collection of system and user buttons, and two Qw/ST connectors for adding external sensors and devices. Woha!
You can buy one here: https://shop.pimoroni.com/products/galactic-unicorn
## These are not your everyday RGB LEDs!
Internally Galactic Unicorn applies gamma correction to the supplied image data and updates the display with 14-bit precision resulting in extremely linear visual output - including at the low end.
@ -17,9 +19,9 @@ The Galactic Unicorn library provides a collection of methods that allow you to
Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/pimoroni-pico/tree/main/libraries/pico_graphics) library which provides a comprehensive selection of drawing methods - once your drawing work is complete you pass the PicoGraphics object to Galactic Unicorn to have it displayed on the screen.
- [Example Program](#example-program)
- [Interleaved framebuffer](#interleaved-framebuffer)
- [Interleaved Framebuffer](#interleaved-framebuffer)
- [Function Reference](#function-reference)
- [System state](#system-state)
- [System State](#system-state)
- [`void init()`](#void-init)
- [`void set_brightness(float value)`](#void-set_brightnessfloat-value)
- [`float get_brightness()`](#float-get_brightness)
@ -55,7 +57,7 @@ The following example shows how to scroll a simple message across the display.
using namespace pimoroni;
// create a PicoGraphics framebuffer to draw into
PicoGraphics_PenRGB888 graphics(53, 11, nullptr);
PicoGraphics_PenRGB888 graphics(GalacticUnicorn::WIDTH, GalacticUnicorn::HEIGHT, nullptr);
// create our GalacticUnicorn object
GalacticUnicorn galactic_unicorn;
@ -71,14 +73,14 @@ int main() {
galactic_unicorn.init();
// start position for scrolling (off the side of the display)
float scroll = -53.0f;
float scroll = -(float)GalacticUnicorn::WIDTH;
while(true) {
// determine the scroll position of the text
int width = graphics.measure_text(message, 1);
scroll += 0.25f;
if(scroll > width) {
scroll = -53.0f;
scroll = -(float)GalacticUnicorn::WIDTH;
}
// clear the graphics object
@ -99,7 +101,7 @@ int main() {
}
```
# Interleaved framebuffer
# Interleaved Framebuffer
Galactic Unicorn takes advantage of the RP2040's PIOs to drive screen updates - this is what gives it the performance it needs to render with 14-bit precision at over 300 frames per second.
@ -123,7 +125,7 @@ If you're working with our library then you don't need to worry about any of the
# Function Reference
## System state
## System State
### `void init()`
@ -131,15 +133,15 @@ Initialise the Galactic Unicorn hardware, interleaved framebuffer, and PIO progr
### `void set_brightness(float value)`
Set the brightness - `value` is supplied as a floating point value between `0..1`.
Set the brightness - `value` is supplied as a floating point value between `0.0` and `1.0`.
### `float get_brightness()`
Returns the current brightness as a value between `0..1`.
Returns the current brightness as a value between `0.0` to `1.0`.
### `void adjust_brightness(float delta)`
Adjust the brightness of the display - `delta` is supplied as a floating point value and will be added to the current brightness (and then clamped to the range `0..1`).
Adjust the brightness of the display - `delta` is supplied as a floating point value and will be added to the current brightness (and then clamped to the range `0.0` to `1.0`).
For example:
@ -152,15 +154,15 @@ galactic.adjust_brightness(-0.2f); // brightness is now 0.8
### `void set_volume(float value)`
Set the volume - `value` is supplied as a floating point value between `0..1`.
Set the volume - `value` is supplied as a floating point value between `0.0` and `1.0`.
### `float get_volume()`
Returns the current volume as a value between `0..1`.
Returns the current volume as a value between `0.0` and `1.0`.
### `void adjust_volume(float delta)`
Adjust the volume - `delta` is supplied as a floating point value and will be added to the current volume (and then clamped to the range `0..1`).
Adjust the volume - `delta` is supplied as a floating point value and will be added to the current volume (and then clamped to the range `0.0` to `1.0`).
For example:
@ -173,7 +175,7 @@ galactic.adjust_volume(-0.2f); // volume is now 0.8
### `uint16_t light()`
Get the current value seen by the onboard light sensor as a value between `0...4096`.
Get the current value seen by the onboard light sensor as a value between `0` and `4095`.
### `bool is_pressed(uint8_t button)`
@ -196,7 +198,7 @@ static const uint8_t SWITCH_BRIGHTNESS_DOWN = 26;
For example:
```c++
while(!galactic.is_pressed(GalacticUnicorn.SWITCH_A)) {
while(!galactic.is_pressed(GalacticUnicorn::SWITCH_A)) {
// wait for switch A to be pressed
}
printf("We did it! We pressed switch A! Heck yeah!");
@ -208,21 +210,25 @@ printf("We did it! We pressed switch A! Heck yeah!");
**This is our recommended way to update the image on Galactic Unicorn.** The PicoGraphics library provides a collection of powerful drawing methods to make things simple.
The image on the PicoGraphics object provided is copied to the interleaved framebuffer with gamma correction applied.
The image on the PicoGraphics object provided is copied to the interleaved framebuffer with gamma correction applied. This lets you have multiple PicoGraphics objects on the go at once and switch between them by changing which gets passed into this function.
If however you'd rather twiddle individual pixels (for example you're producing some sort of algorithmic output) then you can simply use the `clear()` and `update()` methods mentioned below.
If however you'd rather twiddle individual pixels (for example you're producing some sort of algorithmic output) then you can simply use the `clear()` and `set_pixel()` methods mentioned below.
### `void clear()`
Clear the contents of the interleaved framebuffer. If you're using PicoGraphics to build your image (recommended!) then you won't need to call this method as you'll overwrite the entire dispaly when you call `update()` anyway.
Clear the contents of the interleaved framebuffer. This will make your Galactic Unicorn display turn off when the next frame is displayed.
If you're using PicoGraphics to build your image (recommended!) then you won't need to call this method as you'll overwrite the entire display when you call `update()` anyway.
### `void set_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b)`
Set a single pixel to the specified colour. Pixel coordinates go from `0..52` along the `x` axis and from `0..10` on the `y` axis. Colour values are specified as a `0..255` RGB triplet - the supplied colour will be gamma corrected automatically.
Set a single pixel to the specified colour. The newly set colour will be shown at the next frame. Pixel coordinates go from `0` to `52` along the `x` axis and from `0` to `10` on the `y` axis. Colour values are specified as a `0` to `255` RGB triplet - the supplied colour will be gamma corrected automatically.
When drawing a full image it's recommended that you keep the time between each `set_pixel` call short to ensure your image gets displayed on the next frame. Otherwise you can get scanning-like visual artefacts (unless that is your intention of course!)
## Audio
Audio functionality is supported by our [PicoSynth library](https://github.com/pimoroni/pimoroni-pico/tree/main/libraries/pico_synth) which allows you to create multiple voice channels with ADSR envelopes. It provides a similar set of functionality to the classic SID chip in the Commodore 64.
Audio functionality is supported by our [PicoSynth library](https://github.com/pimoroni/pimoroni-pico/tree/main/libraries/pico_synth) which allows you to create multiple voice channels with ADSR (attack decay sustain release) envelopes. It provides a similar set of functionality to the classic SID chip in the Commodore 64.
### `void play_sample(uint8_t *data, uint32_t length)`
@ -240,7 +246,6 @@ Start the synth playing.
Stops any currently playing audio.
## Constants
### `WIDTH` & `HEIGHT`
@ -250,5 +255,5 @@ The width and height of Galactic Unicorn are available in constants `WIDTH` and
For example:
```c++
int num_pixels = GalacticUnicorn.WIDTH * GalacticUnicorn.HEIGHT;
int num_pixels = GalacticUnicorn::WIDTH * GalacticUnicorn::HEIGHT;
```

Wyświetl plik

@ -104,9 +104,7 @@ namespace pimoroni {
float get_volume();
void adjust_volume(float delta);
private:
void set_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b);
public:
uint16_t light();

Wyświetl plik

@ -0,0 +1,131 @@
# Galactic Unicorn MicroPython Examples <!-- omit in toc -->
- [About Galactic Unicorn](#about-galactic-unicorn)
- [Galactic Unicorn and PicoGraphics](#galactic-unicorn-and-picographics)
- [Examples](#examples)
- [Clock](#clock)
- [Eighties Super Computer](#eighties-super-computer)
- [Feature Test](#feature-test)
- [Feature Test With Audio](#feature-test-with-audio)
- [Fire Effect](#fire-effect)
- [Lava Lamp](#lava-lamp)
- [Nostalgia Prompt](#nostalgia-prompt)
- [Rainbow](#rainbow)
- [Scrolling Text](#scrolling-text)
- [Wireless Examples](#wireless-examples)
- [Cheerlights History](#cheerlights-history)
- [Galactic Paint](#galactic-paint)
- [Other Examples](#other-examples)
- [Launch (Demo Reel)](#launch-demo-reel)
## About Galactic Unicorn
Galactic Unicorn offers 53x11 bright RGB LEDs driven by Pico W's PIO in addition to a 1W amplifier + speaker, a collection of system and user buttons, and two Qw/ST connectors for adding external sensors and devices. Woha!
- :link: [Galactic Unicorn store page](https://shop.pimoroni.com/products/galactic-unicorn)
Galactic Unicorn ships with MicroPython firmware pre-loaded, but you can download the most recent version at the link below (you'll want the `galactic-unicorn` image).
- [MicroPython releases](https://github.com/pimoroni/pimoroni-pico/releases)
- [Installing MicroPython](../../../setting-up-micropython.md)
## Galactic Unicorn and PicoGraphics
The easiest way to start displaying cool stuff on Galactic Unicorn is using our Galactic Unicorn module (which contains a bunch of helpful functions for interacting with the buttons, adjusting brightness and suchlike) and our PicoGraphics library, which is chock full of useful functions for drawing on the LED matrix.
- [Galactic Unicorn function reference](../../modules/galactic_unicorn/README.md)
- [PicoGraphics function reference](../../modules/picographics/README.md)
## Examples
### Clock
[clock.py](clock.py)
Clock example with (optional) NTP synchronization. You can adjust the brightness with LUX + and -, and resync the time by pressing A.
### Eighties Super Computer
[eighties_super_computer.py](eighties_super_computer.py)
Random LEDs blink on and off mimicing the look of a movie super computer doing its work in the eighties. You can adjust the brightness with LUX + and -.
### Feature Test
[feature_test.py](feature_test.py)
Displays some text, gradients and colours and demonstrates button use. You can adjust the brightness with LUX + and -.
### Feature Test With Audio
[feature_test_with_audio.py](feature_test_with_audio.py)
Displays some text, gradients and colours and demonstrates button use. Also demonstrates some of the audio / synth features.
- Button A plays a synth tune
- Button B plays a solo channel of the synth tune
- Button C plays a sinewave (it's frequency can be adjusted with VOL + and -)
- Button D plays a second sinewave (it's frequency can be adjusted with LUX + and -)
- Sleep button stops the sounds
### Fire Effect
[fire_effect.py](fire_effect.py)
A pretty, procedural fire effect. Switch between landscape fire and vertical fire using the A and B buttons! You can adjust the brightness with LUX + and -.
### Lava Lamp
[lava_lamp.py](lava_lamp.py)
A 70s-tastic, procedural rainbow lava lamp. You can adjust the brightness with LUX + and -.
### Nostalgia Prompt
[nostalgia_prompt.py](nostalgia_prompt.py)
A collection of copies of classic terminal styles including C64, MS-DOS, Spectrum, and more. Images and text are drawn pixel by pixel from a pattern of Os and Xs. You can adjust the brightness with LUX + and -.
### Rainbow
[rainbow.py](rainbow.py)
Some good old fashioned rainbows! You can adjust the cycling speed with A and B, stripe width with C and D, hue with VOL + and -, and the brightness with LUX + and -. The sleep button stops the animation (can be started again with A or B).
### Scrolling Text
[scrolling_text.py](scrolling_text.py)
Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -.
## Wireless Examples
These examples need `WIFI_CONFIG.py` (from the `common` directory) to be saved to your Pico W. Open up `WIFI_CONFIG.py` in Thonny to add your wifi details (and save it when you're done).
- [micropython/examples/common](../../examples/common)
### Cheerlights History
[cheerlights_history.py](cheerlights_history.py)
Updates one pixel every five minutes to display the most recent #Cheerlights colour. Discover the most popular colours over time, or use it as an avant garde (but colourful) 53 hour clock! Find out more about the Cheerlights API at https://cheerlights.com/
Requires `WIFI_CONFIG.py` and `network_manager.py` from the `common` directory.
You can adjust the brightness with LUX + and -.
### Galactic Paint
[galactic_paint](galactic_paint)
Draw on your Galactic Unicorn from another device in real time, over wifi!
Requires `WIFI_CONFIG.py` from the `common` directory. It also needs the `micropython-phew` and `microdot` libraries (you can install these using Thonny's 'Tools > Manage Packages').
## Other Examples
### Launch (Demo Reel)
[launch](launch)
If you want to get the demo reel that Galactic Unicorn ships with back, copy the contents of this `launch` folder to your Pico W.

Wyświetl plik

@ -0,0 +1,129 @@
# This Galactic Unicorn example updates a pixel every five(ish) minutes
# to display the most recent #cheerlights colour. Discover the most popular
# colours over time, or use it as an avant garde (but colourful) 53 hour clock!
# Find out more about the Cheerlights API at https://cheerlights.com/
#
# To run this example you'll need WIFI_CONFIG.py and network_manager.py from
# the pimoroni-pico micropython/examples/common folder
import WIFI_CONFIG
from network_manager import NetworkManager
import uasyncio
import urequests
import time
from machine import Timer, Pin
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
URL = 'http://api.thingspeak.com/channels/1417/field/2/last.json'
UPDATE_INTERVAL = 327 # refresh interval in secs. Be nice to free APIs!
# this esoteric number is used so that a column of LEDs equates (approximately) to an hour
def status_handler(mode, status, ip):
# reports wifi connection status
print(mode, status, ip)
print('Connecting to wifi...')
if status is not None:
if status:
print('Wifi connection successful!')
else:
print('Wifi connection failed!')
def hex_to_rgb(hex):
# converts a hex colour code into RGB
h = hex.lstrip('#')
r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4))
return r, g, b
def get_data():
# open the json file
print(f'Requesting URL: {URL}')
r = urequests.get(URL)
# open the json data
j = r.json()
print('Data obtained!')
r.close()
# flash the onboard LED after getting data
pico_led.value(True)
time.sleep(0.2)
pico_led.value(False)
# extract hex colour from the json data
hex = j['field2']
# add the new hex colour to the end of the array
colour_array.append(hex)
print(f'Colour added to array: {hex}')
# remove the oldest colour in the array
colour_array.pop(0)
update_leds()
def update_leds():
# light up the LEDs
# this step takes a second, it's doing a lot of hex_to_rgb calculations!
print("Updating LEDs...")
i = 0
for x in range(width):
for y in range(height):
r = hex_to_rgb(colour_array[i])[0]
g = hex_to_rgb(colour_array[i])[1]
b = hex_to_rgb(colour_array[i])[2]
current_colour = graphics.create_pen(r, g, b)
graphics.set_pen(current_colour)
graphics.pixel(x, y)
i = i + 1
gu.update(graphics)
print("LEDs updated!")
gu = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)
width = GalacticUnicorn.WIDTH
height = GalacticUnicorn.HEIGHT
gu.set_brightness(0.5)
# set up the Pico W's onboard LED
pico_led = Pin('LED', Pin.OUT)
current_colour = graphics.create_pen(0, 0, 0)
# set up an list to store the colours
colour_array = ["#000000"] * 583
# set up wifi
try:
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK))
except Exception as e:
print(f'Wifi connection failed! {e}')
# get the first lot of data
get_data()
# start timer (the timer will call the function to update our data every UPDATE_INTERVAL)
timer = Timer(-1)
timer.init(period=UPDATE_INTERVAL * 1000, mode=Timer.PERIODIC, callback=lambda t: get_data())
while True:
# adjust brightness with LUX + and -
# LEDs take a couple of secs to update, so adjust in big (10%) steps
if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_UP):
gu.adjust_brightness(+0.1)
update_leds()
print(f"Brightness set to {gu.get_brightness()}")
if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_DOWN):
gu.adjust_brightness(-0.1)
update_leds()
print(f"Brightness set to {gu.get_brightness()}")
# pause for a moment (important or the USB serial device will fail)
time.sleep(0.001)

Wyświetl plik

@ -3,6 +3,13 @@ import random
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
Random LEDs blink on and off mimicing the look of a movie
super computer doing its work in the eighties.
You can adjust the brightness with LUX + and -.
'''
gu = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)

Wyświetl plik

@ -3,6 +3,12 @@ import math
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
Displays some text, gradients and colours and demonstrates button use.
You can adjust the brightness with LUX + and -.
'''
gu = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)

Wyświetl plik

@ -5,6 +5,17 @@ from machine import Timer
from galactic import GalacticUnicorn, Channel
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
Displays some text, gradients and colours and demonstrates button use.
Also demonstrates some of the audio / synth features.
- Button A plays a synth tune
- Button B plays a solo channel of the synth tune
- Button C plays a sinewave (it's frequency can be adjusted with VOL + and -)
- Button D plays a second sinewave (it's frequency can be adjusted with LUX + and -)
- Sleep button stops the sounds
'''
gc.collect()
gu = GalacticUnicorn()

Wyświetl plik

@ -3,6 +3,13 @@ import random
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
A pretty, procedural fire effect.
Switch between landscape fire and vertical fire using the A and B buttons!
You can adjust the brightness with LUX + and -.
'''
gu = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)

Wyświetl plik

@ -4,6 +4,12 @@ import math
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
A 70s-tastic, procedural rainbow lava lamp.
You can adjust the brightness with LUX + and -.
'''
gu = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)

Wyświetl plik

@ -2,6 +2,14 @@ import time
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
A collection of copies of classic terminal styles including
C64, MS-DOS, Spectrum, and more. Images and text are drawn
pixel by pixel from a pattern of Os and Xs.
You can adjust the brightness with LUX + and -.
'''
gu = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)

Wyświetl plik

@ -3,6 +3,15 @@ import math
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
Some good old fashioned rainbows!
You can adjust the cycling speed with A and B,
stripe width with C and D, hue with VOL + and -,
and the brightness with LUX + and -.
The sleep button stops the animation (can be started again with A or B).
'''
gu = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)

Wyświetl plik

@ -2,6 +2,12 @@ import time
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
'''
Display scrolling wisdom, quotes or greetz.
You can adjust the brightness with LUX + and -.
'''
# constants for controlling scrolling text
PADDING = 5
MESSAGE_COLOUR = (255, 255, 255)

Wyświetl plik

@ -0,0 +1,315 @@
# Galactic Unicorn (MicroPython) <!-- omit in toc -->
Galactic Unicorn offers 53x11 bright RGB LEDs driven by Pico W's PIO in addition to a 1W amplifier + speaker, a collection of system and user buttons, and two Qw/ST connectors for adding external sensors and devices. Woha!
You can buy one here: https://shop.pimoroni.com/products/galactic-unicorn
## These are not your everyday RGB LEDs!
Internally Galactic Unicorn applies gamma correction to the supplied image data and updates the display with 14-bit precision resulting in extremely linear visual output - including at the low end.
The display is refreshed around 300 times per second (300fps!) allowing for rock solid stability even when being filmed, no smearing or flickering even when in motion.
No strobing or brightness stepping here folks - it's the perfect backdrop for your tricked out streaming setup!
## Getting started
The Galactic Unicorn library provides a collection of methods that allow you to easily access all of the features on the board.
Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/modules/picographics) library which provides a comprehensive selection of drawing methods - once your drawing work is complete you pass the PicoGraphics object to Galactic Unicorn to have it displayed on the screen.
- [Example Program](#example-program)
- [Interleaved Framebuffer](#interleaved-framebuffer)
- [Function Reference](#function-reference)
- [Imports and Objects](#imports-and-objects)
- [System State](#system-state)
- [`set_brightness(value)`](#set_brightnessvalue)
- [`get_brightness()`](#get_brightness)
- [`adjust_brightness(delta)`](#adjust_brightnessdelta)
- [`set_volume(value)`](#set_volumevalue)
- [`get_volume()`](#get_volume)
- [`adjust_volume(delta)`](#adjust_volumedelta)
- [`light()`](#light)
- [`is_pressed(button)`](#is_pressedbutton)
- [Drawing](#drawing)
- [`update(PicoGraphics)`](#updatepicographics)
- [`clear()`](#clear)
- [Audio](#audio)
- [`play_sample(data)`](#play_sampledata)
- [`synth_channel(channel)`](#synth_channelchannel)
- [`play_synth()`](#play_synth)
- [`stop_playing()`](#stop_playing)
- [Channel Reference](#channel-reference)
- [Constants](#constants)
- [`WIDTH` & `HEIGHT`](#width--height)
- [Using Breakouts](#using-breakouts)
# Example Program
The following example shows how to scroll a simple message across the display.
```python
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN
import time
# create a PicoGraphics framebuffer to draw into
graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN)
# create our GalacticUnicorn object
gu = GalacticUnicorn()
# start position for scrolling (off the side of the display)
scroll = float(-GalacticUnicorn.WIDTH)
# message to scroll
MESSAGE = "Pirate. Monkey. Robot. Ninja."
# pen colours to draw with
BLACK = graphics.create_pen(0, 0, 0)
YELLOW = graphics.create_pen(255, 255, 0)
while True:
# determine the scroll position of the text
width = graphics.measure_text(MESSAGE, 1)
scroll += 0.25
if scroll > width:
scroll = float(-GalacticUnicorn.WIDTH)
# clear the graphics object
graphics.set_pen(BLACK)
graphics.clear()
# draw the text
graphics.set_pen(YELLOW)
graphics.text(MESSAGE, round(0 - scroll), 2, -1, 0.55);
# update the display
gu.update(graphics)
time.sleep(0.02)
```
# Interleaved Framebuffer
Galactic Unicorn takes advantage of the RP2040's PIOs to drive screen updates - this is what gives it the performance it needs to render with 14-bit precision at over 300 frames per second.
The PIO is a powerful, but limited, tool. It has no way to access memory at random and minimal support for decision making and branching. All it can really do is process a stream of data/instructions in order.
This means that we need to be clever about the way we pass data into the PIO program, the information needs to be delivered in the exact order that the PIO will need to process it. To achieve this we "interleave" our framebuffer - each frame of BCM data is passed one after another with values for the current row, pixel count, and timing inserted as needed:
row 0 data:
for each bcd frame:
bit : data
0: 00110110 // row pixel count (minus one)
1 - 53: xxxxxbgr, xxxxxbgr, xxxxxbgr, ... // pixel data
54 - 55: xxxxxxxx, xxxxxxxx // dummy bytes to dword align
56: xxxxrrrr // row select bits
57 - 59: tttttttt, tttttttt, tttttttt // bcd tick count (0-65536)
row 1 data:
...
If you're working with our library then you don't need to worry about any of these details, they are handled for you.
# Function Reference
## Imports and Objects
To access these functions, you'll need to first `import` the relevant libraries and then set up a Galactic Unicorn object:
```python
from galactic import GalacticUnicorn
gu = GalacticUnicorn()
```
or (with PicoGraphics):
```python
from galactic import GalacticUnicorn
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN
gu = GalacticUnicorn()
graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN)
```
## System State
### `set_brightness(value)`
Set the brightness - `value` is supplied as a floating point value between `0.0` and `1.0`.
### `get_brightness()`
Returns the current brightness as a value between `0.0` and `1.0`.
### `adjust_brightness(delta)`
Adjust the brightness of the display - `delta` is supplied as a floating point value and will be added to the current brightness (and then clamped to the range `0.0` to `1.0`).
For example:
```python
gu.set_brightness(0.5)
gu.adjust_brightness(0.1) # brightness is now 0.6
gu.adjust_brightness(0.7) # brightness is now 1.0
gu.adjust_brightness(-0.2) # brightness is now 0.8
```
### `set_volume(value)`
Set the volume - `value` is supplied as a floating point value between `0.0` and `1.0`.
### `get_volume()`
Returns the current volume as a value between `0.0` and `1.0`.
### `adjust_volume(delta)`
Adjust the volume - `delta` is supplied as a floating point value and will be added to the current volume (and then clamped to the range `0.0` to `1.0`).
For example:
```python
gu.set_volume(0.5)
gu.set_volume(0.1) # volume is now 0.6
gu.adjust_volume(0.7) # volume is now 1.0
gu.adjust_volume(-0.2) # volume is now 0.8
```
### `light()`
Get the current value seen by the onboard light sensor as a value between `0` and `4095`.
### `is_pressed(button)`
Returns true if the requested `button` is currently pressed.
There are a set of constants in the GalacticUnicorn class that represent each of the buttons. The brightness, sleep, and volume buttons are not tied to hardware functions (they are implemented entirely in software) so can also be used for user functions if preferred. Here's a list of the constants and their associated pin numbers:
```python
SWITCH_A = 0
SWITCH_B = 1
SWITCH_C = 3
SWITCH_D = 6
SWITCH_SLEEP = 27
SWITCH_VOLUME_UP = 7
SWITCH_VOLUME_DOWN = 8
SWITCH_BRIGHTNESS_UP = 21
SWITCH_BRIGHTNESS_DOWN = 26
```
For example:
```python
while not gu.is_pressed(GalacticUnicorn.SWITCH_A):
# wait for switch A to be pressed
pass
print("We did it! We pressed switch A! Heck yeah!")
```
## Drawing
### `update(PicoGraphics)`
The PicoGraphics library provides a collection of powerful drawing methods to make things simple.
The image on the PicoGraphics object provided is copied to the interleaved framebuffer with gamma correction applied.
For example (assuming you've set up your Galactic Unicorn and PicoGraphics objects up [as we did above](#imports-and-objects)):
```python
gu.update(graphics)
```
⚠️ If you've used PicoGraphics on our other boards note that this `update` function works a little differently. Here it's a Galactic Unicorn function to which you need to pass a PicoGraphics object to.
### `clear()`
Clear the contents of the interleaved framebuffer. This will make your Galactic Unicorn display turn off. To show an image again, call the `update()` function as described above.
## Audio
Audio functionality is supported by our [PicoSynth library](https://github.com/pimoroni/pimoroni-pico/tree/main/libraries/pico_synth) which allows you to create multiple voice channels with ADSR (attack decay sustain release) envelopes. It provides a similar set of functionality to the classic SID chip in the Commodore 64.
### `play_sample(data)`
Play the provided 16-bit audio sample. `data` must point to a `bytearray` that contains 16-bit PCM data. The number of samples is retrieved from the array's length.
### `synth_channel(channel)`
Gets a `Channel` object which can then be configured with voice, ADSR envelope, etc.
### `play_synth()`
Start the synth playing.
### `stop_playing()`
Stops any currently playing audio.
### Channel Reference
```python
configure(waveforms=None, frequency=None, volume=None,
attack=None, decay=None, sustain=None,
release=None, pulse_width=None)
restore()
waveforms()
waveforms(waveforms)
frequency()
frequency(frequency)
volume()
volume(volume)
attack_duration()
attack_duration(duration)
decay_duration()
decay_duration(duration)
sustain_level()
sustain_level(level)
release_duration()
release_duration(duration)
pulse_width()
pulse_width(width)
trigger_attack() # start the channel playing
trigger_release() # stop the channel playing
play_tone(frequency, volume=None, attack=None, release=None)
```
## Constants
### `WIDTH` & `HEIGHT`
The width and height of Galactic Unicorn are available in constants `WIDTH` and `HEIGHT`.
For example:
```python
num_pixels = GalacticUnicorn.WIDTH * GalacticUnicorn.HEIGHT
print(num_pixels)
```
## Using Breakouts
Galactic Unicorn has two Qw/ST (Qwiic/STEMMA QT) connectors. Breakouts with Qw/ST connectors, can be plugged straight in with a [JST-SH to JST-SH cable](https://shop.pimoroni.com/products/jst-sh-cable-qwiic-stemma-qt-compatible?variant=31910609813587). You can connect I2C Breakout Garden breakouts without Qw/ST connectors using a [JST-SH to JST-SH cable](https://shop.pimoroni.com/products/jst-sh-cable-qwiic-stemma-qt-compatible?variant=31910609813587) and a [Qw/ST to Breakout Garden adaptor](https://shop.pimoroni.com/products/stemma-qt-qwiic-to-breakout-garden-adapter).
- [List of breakouts currently supported in our C++/MicroPython build](https://github.com/pimoroni/pimoroni-pico#breakouts)
Galactic Unicorn uses GP4 and GP5 for its I2C interface. You can use the constants in the shared `pimoroni` module to set up the I2C interface:
```python
from pimoroni_i2c import PimoroniI2C
from pimoroni import PINS_BREAKOUT_GARDEN
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
```
Alternatively, you can specify the pin numbers directly:
```python
from pimoroni_i2c import PimoroniI2C
i2c = PimoroniI2C(sda=4, scl=5)
```

Wyświetl plik

@ -14,7 +14,7 @@ Pico Graphics replaces the individual drivers for displays- if you're been using
- [Function Reference](#function-reference)
- [General](#general)
- [Creating & Setting Pens](#creating--setting-pens)
- [RGB565, RGB332, P8 and P4 modes](#rgb565-rgb332-p8-and-p4-modes)
- [RGB888, RGB565, RGB332, P8 and P4 modes](#rgb888-rgb565-rgb332-p8-and-p4-modes)
- [Monochrome Modes](#monochrome-modes)
- [Inky Frame](#inky-frame)
- [Controlling The Backlight](#controlling-the-backlight)
@ -64,6 +64,7 @@ Bear in mind that MicroPython has only 192K of RAM available- a 320x240 pixel di
* Pico Inky Pack - 296x128 mono e-ink - `DISPLAY_INKY_PACK`
* Inky Frame - 600x447 7-colour e-ink - `DISPLAY_INKY_FRAME`
* Pico GFX Pack - 128x64 mono LCD Matrix - `DISPLAY_GFX_PACK`
* Galactic Unicorn - 53x11 LED Matrix - `DISPLAY_GALACTIC_UNICORN`
### Supported Graphics Modes (Pen Type)
@ -73,6 +74,7 @@ Bear in mind that MicroPython has only 192K of RAM available- a 320x240 pixel di
* 8-bit - `PEN_P8` - 256-colour palette of your choice
* 8-bit RGB332 - `PEN_RGB332` - 256 fixed colours (3 bits red, 3 bits green, 2 bits blue)
* 16-bit RGB565 - `PEN_RGB565` - 64K colours at the cost of RAM. (5 bits red, 6 bits green, 5 bits blue)
* 24-bit RGB888 - `PEN_RGB888` - 16M colours at the cost of lots of RAM. (8 bits red, 8 bits green, 8 bits blue)
These offer a tradeoff between RAM usage and available colours. In most cases you would probably use `RGB332` since it offers the easiest tradeoff. It's also the default for colour LCDs.
@ -136,7 +138,7 @@ display = PicoGraphics(display=DISPLAY_I2C_OLED_128X128, bus=i2cbus)
#### Creating & Setting Pens
##### RGB565, RGB332, P8 and P4 modes
##### RGB888, RGB565, RGB332, P8 and P4 modes
Create a pen colour for drawing into a screen:
@ -154,7 +156,7 @@ To tell PicoGraphics which pen to use:
display.set_pen(my_pen)
```
This will be either an RGB332 or RGB565 colour, or a palette index.
This will be either an RGB332, RGB565 or RGB888 colour, or a palette index.
##### Monochrome Modes
@ -243,6 +245,12 @@ Send the contents of your Pico Graphics buffer to your screen:
display.update()
```
If you are using a Galactic Unicorn, then the process for updating the display is different. Instead of the above, do:
```python
galactic_unicorn.update(display)
```
### Text
#### Changing The Font