From 987f98f7cadad72c5b9689bad5f23e60554f96f9 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Tue, 1 Nov 2022 16:53:47 +0000 Subject: [PATCH 01/19] update readme --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0f886e59..9622fceb 100644 --- a/README.md +++ b/README.md @@ -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) From 738531ebcf6d6ab2d244f807f9f030a10d43df8b Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:51:45 +0000 Subject: [PATCH 02/19] add micropython function reference --- .../modules/galactic_unicorn/README.md | 253 ++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 micropython/modules/galactic_unicorn/README.md diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md new file mode 100644 index 00000000..9aec24d4 --- /dev/null +++ b/micropython/modules/galactic_unicorn/README.md @@ -0,0 +1,253 @@ +# Galactic Unicorn (MicroPython) + +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! + +## 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) + - [Audio](#audio) + - [`play_sample(data, length)`](#play_sampledata-length) + - [`synth_channel(channel)`](#synth_channelchannel) + - [`play_synth()`](#play_synth) + - [`stop_playing()`](#stop_playing) + - [Constants](#constants) + - [`WIDTH` & `HEIGHT`](#width--height) + +# 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 = -53.0 + +# 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 = -53.0 + + # 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..1`. + +### `get_brightness()` + +Returns the current brightness as a value between `0..1`. + +### `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..1`). + +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..1`. + +### `get_volume()` + +Returns the current volume as a value between `0..1`. + +### `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..1`). + +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...4096`. + +### `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 gu.is_pressed(gu.SWITCH_A): + # wait for switch A to be pressed + print("We did it! We pressed switch A! Heck yeah!") +``` + +## Drawing + +### `update(PicoGraphics)` + +**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. + +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's it's a Galactic Unicorn function to which you need to pass a PicoGraphics object). + +## 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. + +### `play_sample(data, length)` + +Play the provided 16-bit audio sample. `data` must point to a buffer that contains 16-bit PCM data and `length` must be the number of samples. + +### `synth_channel(channel)` + +Gets an `AudioChannel` object which can then be configured with voice, ADSR envelope, etc. + +### `play_synth()` + +Start the synth playing. + +### `stop_playing()` + +Stops any currently playing audio. + +## Constants + +### `WIDTH` & `HEIGHT` + +The width and height of Galactic Unicorn are available in constants `WIDTH` and `HEIGHT`. + +For example: + +```python +num_pixels = gu.WIDTH * gu.HEIGHT +print(num_pixels) +``` \ No newline at end of file From 79a2349fac40c3ab723980c6c58159081dd0d7a0 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:45:14 +0000 Subject: [PATCH 03/19] update micropython function reference --- micropython/modules/galactic_unicorn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index 9aec24d4..d83ef71c 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -211,7 +211,7 @@ while gu.is_pressed(gu.SWITCH_A): 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): +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) From cac74a94bb23bd42678953aece27584eff7a4824 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:47:41 +0000 Subject: [PATCH 04/19] update function reference --- micropython/modules/galactic_unicorn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index d83ef71c..96025be3 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -211,7 +211,7 @@ while gu.is_pressed(gu.SWITCH_A): 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): +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) From 689326ac558ace212b106200ada6c7f3ecd2a409 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Wed, 2 Nov 2022 14:56:08 +0000 Subject: [PATCH 05/19] update function reference --- micropython/modules/galactic_unicorn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index 96025be3..82dc307e 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -217,7 +217,7 @@ For example (assuming you've set up your Galactic Unicorn and PicoGraphics objec gu.update(graphics) ``` -⚠️ If you've used PicoGraphics on our other boards note that this `update` function works a little differently (here's it's a Galactic Unicorn function to which you need to pass a PicoGraphics object). +⚠️ 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). ## Audio From 347cd19ab97c6ce241d56850056aef37007b935d Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:58:18 +0000 Subject: [PATCH 06/19] update GU readmes --- .../examples/galactic_unicorn/README.md | 108 ++++++++++++++++++ .../modules/galactic_unicorn/README.md | 26 +++++ 2 files changed, 134 insertions(+) create mode 100644 micropython/examples/galactic_unicorn/README.md diff --git a/micropython/examples/galactic_unicorn/README.md b/micropython/examples/galactic_unicorn/README.md new file mode 100644 index 00000000..b592afad --- /dev/null +++ b/micropython/examples/galactic_unicorn/README.md @@ -0,0 +1,108 @@ +# Galactic Unicorn MicroPython Examples + +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](#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 Over Time](#cheerlights-over-time) + - [Galactic Paint](#galactic-paint) + +## Galactic Unicorn and PicoGraphics + +The easiest way to start displaying 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/picographics/README.md) +- [PicoGraphics function reference](../../modules/galactic_unicorn/README.md) + +## Examples + +### Clock + +[clock.py](clock.py) + +Clock example with (optional) NTP synchronization. + +### Eighties Super Computer + +[eighties_super_computer.py](eighties_super_computer.py) + +todo + +### Feature Test + +[feature_test.py](feature_test.py) + +todo + +### Feature Test With Audio + +[feature_test_with_audio.py](feature_test_with_audio.py) + +todo + +### Fire Effect + +[fire_effect.py](fire_effect.py) + +todo + +### Lava Lamp + +[lava_lamp.py](lava_lamp.py) + +todo + +### Nostalgia Prompt + +[nostalgia_prompt.py](nostalgia_prompt.py) + +todo + +### Rainbow + +[rainbow.py](rainbow.py) + +Some good old fashioned rainbows! + +### Scrolling Text + +[scrolling_text.py](scrolling_text.py) + +todo + +## Wireless Examples + +### Cheerlights Over Time + +[cheerlights_over_time.py](cheerlights_over_time.py) + +todo + +This wireless example needs `network_manager.py` and `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) + +### Galactic Paint + +[galactic_paint](galactic_paint) + +todo + + diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index 82dc307e..f46aecdf 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -2,6 +2,8 @@ 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. @@ -38,6 +40,7 @@ Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/ - [`stop_playing()`](#stop_playing) - [Constants](#constants) - [`WIDTH` & `HEIGHT`](#width--height) + - [Using Breakouts](#using-breakouts) # Example Program @@ -250,4 +253,27 @@ For example: ```python num_pixels = gu.WIDTH * gu.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 :link:[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 :link:[JST-SH to JST-SH cable](https://shop.pimoroni.com/products/jst-sh-cable-qwiic-stemma-qt-compatible?variant=31910609813587) and a :link:[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)) ``` \ No newline at end of file From 0f5e96495cdbaf0cfb64920c3de190089c6fd3d6 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 14:16:05 +0000 Subject: [PATCH 07/19] add cheerlights history example --- .../galactic_unicorn/cheerlights_history.py | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 micropython/examples/galactic_unicorn/cheerlights_history.py diff --git a/micropython/examples/galactic_unicorn/cheerlights_history.py b/micropython/examples/galactic_unicorn/cheerlights_history.py new file mode 100644 index 00000000..8c8b8171 --- /dev/null +++ b/micropython/examples/galactic_unicorn/cheerlights_history.py @@ -0,0 +1,130 @@ +# 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(): + global n + # 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) From c599ae494181186ec304ddfaa4f1c5d78cb2dc84 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 15:20:28 +0000 Subject: [PATCH 08/19] update examples readme --- .../examples/galactic_unicorn/README.md | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/micropython/examples/galactic_unicorn/README.md b/micropython/examples/galactic_unicorn/README.md index b592afad..b9bcb748 100644 --- a/micropython/examples/galactic_unicorn/README.md +++ b/micropython/examples/galactic_unicorn/README.md @@ -2,7 +2,7 @@ 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) +- :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). @@ -21,12 +21,13 @@ Galactic Unicorn ships with MicroPython firmware pre-loaded, but you can downloa - [Rainbow](#rainbow) - [Scrolling Text](#scrolling-text) - [Wireless Examples](#wireless-examples) - - [Cheerlights Over Time](#cheerlights-over-time) + - [Cheerlights History](#cheerlights-history) - [Galactic Paint](#galactic-paint) +- [Factory reset](#factory-reset) ## Galactic Unicorn and PicoGraphics -The easiest way to start displaying 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. +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/picographics/README.md) - [PicoGraphics function reference](../../modules/galactic_unicorn/README.md) @@ -43,59 +44,59 @@ Clock example with (optional) NTP synchronization. [eighties_super_computer.py](eighties_super_computer.py) -todo +Random LEDs blink on and off mimicing the look of a movie super computer doing its work in the eighties. ### Feature Test [feature_test.py](feature_test.py) -todo +Displays some text, gradients and colours and demonstrates button use. ### Feature Test With Audio [feature_test_with_audio.py](feature_test_with_audio.py) -todo +Displays some text, gradients and colours and demonstrates button use. Also demonstrates some of the audio / synth features. ### Fire Effect [fire_effect.py](fire_effect.py) -todo +A pretty, procedural fire effect. Switch `landscape = False` for vertical fire! ### Lava Lamp [lava_lamp.py](lava_lamp.py) -todo +A 70s-tastic, procedural rainbow lava lamp. ### Nostalgia Prompt [nostalgia_prompt.py](nostalgia_prompt.py) -todo +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. ### Rainbow [rainbow.py](rainbow.py) -Some good old fashioned rainbows! +Some good old fashioned rainbows! You can adjust the cycling speed with VOL + and - and the brightness with LUX + and -. ### Scrolling Text [scrolling_text.py](scrolling_text.py) -todo +Display scrolling wisdom, quotes or greetz. ## Wireless Examples -### Cheerlights Over Time +### Cheerlights History -[cheerlights_over_time.py](cheerlights_over_time.py) +[cheerlights_history.py](cheerlights_history.py) -todo +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/ -This wireless example needs `network_manager.py` and `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). +This example needs `network_manager.py` and `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) @@ -103,6 +104,13 @@ This wireless example needs `network_manager.py` and `WIFI_CONFIG.py` from the ` [galactic_paint](galactic_paint) -todo +Draw on your Galactic Unicorn from another device in real time! +- [Galactic Paint readme](galactic_paint/README.md) + +## Factory reset + +[launch](launch) + +If you want to get the demo reel back, copy the contents of this `launch` folder to your Pico W. From 91505c2976c11e48e64a7aa0d043e5637cfa4277 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 15:31:21 +0000 Subject: [PATCH 09/19] update examples readme --- .../examples/galactic_unicorn/README.md | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/micropython/examples/galactic_unicorn/README.md b/micropython/examples/galactic_unicorn/README.md index b9bcb748..7ac5c314 100644 --- a/micropython/examples/galactic_unicorn/README.md +++ b/micropython/examples/galactic_unicorn/README.md @@ -1,14 +1,6 @@ # Galactic Unicorn MicroPython Examples - -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) - + +- [About Galactic Unicorn](#about-galactic-unicorn) - [Galactic Unicorn and PicoGraphics](#galactic-unicorn-and-picographics) - [Examples](#examples) - [Clock](#clock) @@ -22,8 +14,20 @@ Galactic Unicorn ships with MicroPython firmware pre-loaded, but you can downloa - [Scrolling Text](#scrolling-text) - [Wireless Examples](#wireless-examples) - [Cheerlights History](#cheerlights-history) +- [Other Examples](#other-examples) - [Galactic Paint](#galactic-paint) -- [Factory reset](#factory-reset) + - [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 @@ -90,15 +94,17 @@ Display scrolling wisdom, quotes or greetz. ## Wireless Examples +This example needs `network_manager.py` and `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/ -This example needs `network_manager.py` and `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) +## Other Examples ### Galactic Paint @@ -108,9 +114,9 @@ Draw on your Galactic Unicorn from another device in real time! - [Galactic Paint readme](galactic_paint/README.md) -## Factory reset +### Launch (Demo Reel) [launch](launch) -If you want to get the demo reel back, copy the contents of this `launch` folder to your Pico W. +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. From 080da22b5f1ea1bc440303a83368f407241e9dab Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 15:42:45 +0000 Subject: [PATCH 10/19] update readme --- micropython/examples/galactic_unicorn/README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/micropython/examples/galactic_unicorn/README.md b/micropython/examples/galactic_unicorn/README.md index 7ac5c314..198afe86 100644 --- a/micropython/examples/galactic_unicorn/README.md +++ b/micropython/examples/galactic_unicorn/README.md @@ -14,8 +14,8 @@ - [Scrolling Text](#scrolling-text) - [Wireless Examples](#wireless-examples) - [Cheerlights History](#cheerlights-history) -- [Other Examples](#other-examples) - [Galactic Paint](#galactic-paint) +- [Other Examples](#other-examples) - [Launch (Demo Reel)](#launch-demo-reel) ## About Galactic Unicorn @@ -94,7 +94,7 @@ Display scrolling wisdom, quotes or greetz. ## Wireless Examples -This example needs `network_manager.py` and `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). +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) @@ -104,15 +104,17 @@ This example needs `network_manager.py` and `WIFI_CONFIG.py` (from the `common` 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/ -## Other Examples +Requires `WIFI_CONFIG.py` and `network_manager.py` from the `common` directory. ### Galactic Paint [galactic_paint](galactic_paint) -Draw on your Galactic Unicorn from another device in real time! +Draw on your Galactic Unicorn from another device in real time, over wifi! -- [Galactic Paint readme](galactic_paint/README.md) +Requires `WIFI_CONFIG.py` from the `common` directory plus `micropython-phew` and `microdot` (install these libraries through Thonny's 'Tools > Manage Packages). + +## Other Examples ### Launch (Demo Reel) From 6d98cec7de5a936473e9dab4ebfd1d731c0ed843 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 15:44:43 +0000 Subject: [PATCH 11/19] update examples readme --- micropython/examples/galactic_unicorn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/galactic_unicorn/README.md b/micropython/examples/galactic_unicorn/README.md index 198afe86..156fbd27 100644 --- a/micropython/examples/galactic_unicorn/README.md +++ b/micropython/examples/galactic_unicorn/README.md @@ -112,7 +112,7 @@ Requires `WIFI_CONFIG.py` and `network_manager.py` from the `common` directory. Draw on your Galactic Unicorn from another device in real time, over wifi! -Requires `WIFI_CONFIG.py` from the `common` directory plus `micropython-phew` and `microdot` (install these libraries through Thonny's 'Tools > Manage Packages). +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 From 0e80e1d96aa3d9f954c3d1844c25fb88ea9a1f82 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 15:48:21 +0000 Subject: [PATCH 12/19] update examples readme --- micropython/examples/galactic_unicorn/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/micropython/examples/galactic_unicorn/README.md b/micropython/examples/galactic_unicorn/README.md index 156fbd27..3af29f1f 100644 --- a/micropython/examples/galactic_unicorn/README.md +++ b/micropython/examples/galactic_unicorn/README.md @@ -33,8 +33,8 @@ Galactic Unicorn ships with MicroPython firmware pre-loaded, but you can downloa 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/picographics/README.md) -- [PicoGraphics function reference](../../modules/galactic_unicorn/README.md) +- [Galactic Unicorn function reference](../../modules/galactic_unicorn/README.md) +- [PicoGraphics function reference](../../modules/picographics/README.md) ## Examples From 43195709606e96a8780bb3b27e94c7540dc94935 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 15:57:59 +0000 Subject: [PATCH 13/19] update function reference --- micropython/modules/galactic_unicorn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index f46aecdf..c5ba4a26 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -257,7 +257,7 @@ 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 :link:[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 :link:[JST-SH to JST-SH cable](https://shop.pimoroni.com/products/jst-sh-cable-qwiic-stemma-qt-compatible?variant=31910609813587) and a :link:[Qw/ST to Breakout Garden adaptor](https://shop.pimoroni.com/products/stemma-qt-qwiic-to-breakout-garden-adapter). +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) From c2b695f7e947c1e890e47592357d27ce2794528d Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Thu, 3 Nov 2022 16:44:36 +0000 Subject: [PATCH 14/19] remove unused variable --- micropython/examples/galactic_unicorn/cheerlights_history.py | 1 - 1 file changed, 1 deletion(-) diff --git a/micropython/examples/galactic_unicorn/cheerlights_history.py b/micropython/examples/galactic_unicorn/cheerlights_history.py index 8c8b8171..aed2c552 100644 --- a/micropython/examples/galactic_unicorn/cheerlights_history.py +++ b/micropython/examples/galactic_unicorn/cheerlights_history.py @@ -40,7 +40,6 @@ def hex_to_rgb(hex): def get_data(): - global n # open the json file print(f'Requesting URL: {URL}') r = urequests.get(URL) From d11c73d45eb1890355a13e0e2f8db81cba4cb874 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Fri, 4 Nov 2022 10:57:37 +0000 Subject: [PATCH 15/19] Updated GU readme --- libraries/galactic_unicorn/README.md | 51 +++++----- .../galactic_unicorn/galactic_unicorn.hpp | 2 - .../modules/galactic_unicorn/README.md | 92 +++++++++++++------ 3 files changed, 92 insertions(+), 53 deletions(-) diff --git a/libraries/galactic_unicorn/README.md b/libraries/galactic_unicorn/README.md index 2986c3a3..6d6eab90 100644 --- a/libraries/galactic_unicorn/README.md +++ b/libraries/galactic_unicorn/README.md @@ -1,7 +1,9 @@ -# Galactic Unicorn +# Galactic Unicorn (C/C++) 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; ``` \ No newline at end of file diff --git a/libraries/galactic_unicorn/galactic_unicorn.hpp b/libraries/galactic_unicorn/galactic_unicorn.hpp index 79b39fff..3e598287 100644 --- a/libraries/galactic_unicorn/galactic_unicorn.hpp +++ b/libraries/galactic_unicorn/galactic_unicorn.hpp @@ -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(); diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index c5ba4a26..e0d49a75 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -16,13 +16,13 @@ No strobing or brightness stepping here folks - it's the perfect backdrop for yo 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. +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) +- [Interleaved Framebuffer](#interleaved-framebuffer) - [Function Reference](#function-reference) - - [Imports and objects](#imports-and-objects) - - [System state](#system-state) + - [Imports and Objects](#imports-and-objects) + - [System State](#system-state) - [`set_brightness(value)`](#set_brightnessvalue) - [`get_brightness()`](#get_brightness) - [`adjust_brightness(delta)`](#adjust_brightnessdelta) @@ -33,11 +33,13 @@ Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/ - [`is_pressed(button)`](#is_pressedbutton) - [Drawing](#drawing) - [`update(PicoGraphics)`](#updatepicographics) + - [`clear()`](#clear) - [Audio](#audio) - [`play_sample(data, length)`](#play_sampledata-length) - [`synth_channel(channel)`](#synth_channelchannel) - [`play_synth()`](#play_synth) - [`stop_playing()`](#stop_playing) + - [Channel Function Reference](#channel_function_reference) - [Constants](#constants) - [`WIDTH` & `HEIGHT`](#width--height) - [Using Breakouts](#using-breakouts) @@ -58,7 +60,7 @@ graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN) gu = GalacticUnicorn() # start position for scrolling (off the side of the display) -scroll = -53.0 +scroll = float(-GalacticUnicorn.WIDTH) # message to scroll MESSAGE = "Pirate. Monkey. Robot. Ninja." @@ -72,7 +74,7 @@ while True: width = graphics.measure_text(MESSAGE, 1) scroll += 0.25 if scroll > width: - scroll = -53.0 + scroll = float(-GalacticUnicorn.WIDTH) # clear the graphics object graphics.set_pen(BLACK) @@ -88,7 +90,7 @@ while True: time.sleep(0.02) ``` -# 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. @@ -112,7 +114,7 @@ If you're working with our library then you don't need to worry about any of the # Function Reference -## Imports and objects +## Imports and Objects To access these functions, you'll need to first `import` the relevant libraries and then set up a Galactic Unicorn object: @@ -132,19 +134,19 @@ gu = GalacticUnicorn() graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN) ``` -## System state +## System State ### `set_brightness(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`. ### `get_brightness()` -Returns the current brightness as a value between `0..1`. +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..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: @@ -157,15 +159,15 @@ 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..1`. +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..1`. +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..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: @@ -178,7 +180,7 @@ 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...4096`. +Get the current value seen by the onboard light sensor as a value between `0` and `4095`. ### `is_pressed(button)` @@ -201,38 +203,44 @@ SWITCH_BRIGHTNESS_DOWN = 26 For example: ```python -while gu.is_pressed(gu.SWITCH_A): +while not gu.is_pressed(GalacticUnicorn.SWITCH_A): # wait for switch A to be pressed - print("We did it! We pressed switch A! Heck yeah!") + pass + +print("We did it! We pressed switch A! Heck yeah!") ``` ## Drawing ### `update(PicoGraphics)` -**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 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)): +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) +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). +⚠️ 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. + +### `void 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 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. -### `play_sample(data, length)` +### `play_sample(data)` -Play the provided 16-bit audio sample. `data` must point to a buffer that contains 16-bit PCM data and `length` must be the number of samples. +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 an `AudioChannel` object which can then be configured with voice, ADSR envelope, etc. +Gets a `Channel` object which can then be configured with voice, ADSR envelope, etc. ### `play_synth()` @@ -242,6 +250,34 @@ Start the synth playing. Stops any currently playing audio. +### Channel Function 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` @@ -251,7 +287,7 @@ The width and height of Galactic Unicorn are available in constants `WIDTH` and For example: ```python -num_pixels = gu.WIDTH * gu.HEIGHT +num_pixels = GalacticUnicorn.WIDTH * GalacticUnicorn.HEIGHT print(num_pixels) ``` @@ -275,5 +311,5 @@ Alternatively, you can specify the pin numbers directly: ```python from pimoroni_i2c import PimoroniI2C -i2c = PimoroniI2C(sda=(4), scl=(5)) +i2c = PimoroniI2C(sda=4, scl=5) ``` \ No newline at end of file From c247770f481995393f4d106db20f9d8bb9ebbb98 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Fri, 4 Nov 2022 10:57:53 +0000 Subject: [PATCH 16/19] Updated example descriptions --- .../examples/galactic_unicorn/README.md | 23 ++++++++++++------- .../eighties_super_computer.py | 7 ++++++ .../examples/galactic_unicorn/feature_test.py | 6 +++++ .../feature_test_with_audio.py | 11 +++++++++ .../examples/galactic_unicorn/fire_effect.py | 7 ++++++ .../examples/galactic_unicorn/lava_lamp.py | 6 +++++ .../galactic_unicorn/nostalgia_prompt.py | 8 +++++++ .../examples/galactic_unicorn/rainbow.py | 9 ++++++++ .../galactic_unicorn/scrolling_text.py | 6 +++++ 9 files changed, 75 insertions(+), 8 deletions(-) diff --git a/micropython/examples/galactic_unicorn/README.md b/micropython/examples/galactic_unicorn/README.md index 3af29f1f..677e6bc0 100644 --- a/micropython/examples/galactic_unicorn/README.md +++ b/micropython/examples/galactic_unicorn/README.md @@ -42,55 +42,60 @@ The easiest way to start displaying cool stuff on Galactic Unicorn is using our [clock.py](clock.py) -Clock example with (optional) NTP synchronization. +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. +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. +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 `landscape = False` for vertical fire! +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. +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. +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 VOL + and - and the brightness with LUX + and -. +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. +Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -. ## Wireless Examples @@ -106,6 +111,8 @@ Updates one pixel every five minutes to display the most recent #Cheerlights col 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) diff --git a/micropython/examples/galactic_unicorn/eighties_super_computer.py b/micropython/examples/galactic_unicorn/eighties_super_computer.py index 168ac9c5..501e5eb4 100644 --- a/micropython/examples/galactic_unicorn/eighties_super_computer.py +++ b/micropython/examples/galactic_unicorn/eighties_super_computer.py @@ -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) diff --git a/micropython/examples/galactic_unicorn/feature_test.py b/micropython/examples/galactic_unicorn/feature_test.py index 462a94a4..891076e6 100644 --- a/micropython/examples/galactic_unicorn/feature_test.py +++ b/micropython/examples/galactic_unicorn/feature_test.py @@ -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) diff --git a/micropython/examples/galactic_unicorn/feature_test_with_audio.py b/micropython/examples/galactic_unicorn/feature_test_with_audio.py index ea97e90c..482ce5d5 100644 --- a/micropython/examples/galactic_unicorn/feature_test_with_audio.py +++ b/micropython/examples/galactic_unicorn/feature_test_with_audio.py @@ -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() diff --git a/micropython/examples/galactic_unicorn/fire_effect.py b/micropython/examples/galactic_unicorn/fire_effect.py index 8d801a7b..9c12bd1b 100644 --- a/micropython/examples/galactic_unicorn/fire_effect.py +++ b/micropython/examples/galactic_unicorn/fire_effect.py @@ -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) diff --git a/micropython/examples/galactic_unicorn/lava_lamp.py b/micropython/examples/galactic_unicorn/lava_lamp.py index 49a40f3f..ed577e5c 100644 --- a/micropython/examples/galactic_unicorn/lava_lamp.py +++ b/micropython/examples/galactic_unicorn/lava_lamp.py @@ -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) diff --git a/micropython/examples/galactic_unicorn/nostalgia_prompt.py b/micropython/examples/galactic_unicorn/nostalgia_prompt.py index ca222f91..5cb23aa6 100644 --- a/micropython/examples/galactic_unicorn/nostalgia_prompt.py +++ b/micropython/examples/galactic_unicorn/nostalgia_prompt.py @@ -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) diff --git a/micropython/examples/galactic_unicorn/rainbow.py b/micropython/examples/galactic_unicorn/rainbow.py index 818ee0a1..019132bb 100644 --- a/micropython/examples/galactic_unicorn/rainbow.py +++ b/micropython/examples/galactic_unicorn/rainbow.py @@ -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) diff --git a/micropython/examples/galactic_unicorn/scrolling_text.py b/micropython/examples/galactic_unicorn/scrolling_text.py index 3210dec1..40d8c764 100644 --- a/micropython/examples/galactic_unicorn/scrolling_text.py +++ b/micropython/examples/galactic_unicorn/scrolling_text.py @@ -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) From 3765d43ce0d84982abe80933e2cbfb89a073e489 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Fri, 4 Nov 2022 11:12:20 +0000 Subject: [PATCH 17/19] Link fixes --- micropython/modules/galactic_unicorn/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index e0d49a75..9a31dd25 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -16,7 +16,7 @@ No strobing or brightness stepping here folks - it's the perfect backdrop for yo 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. +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) @@ -35,11 +35,11 @@ Drawing is primarily handled via our [PicoGraphics]https://github.com/pimoroni/p - [`update(PicoGraphics)`](#updatepicographics) - [`clear()`](#clear) - [Audio](#audio) - - [`play_sample(data, length)`](#play_sampledata-length) + - [`play_sample(data)`](#play_sampledata) - [`synth_channel(channel)`](#synth_channelchannel) - [`play_synth()`](#play_synth) - [`stop_playing()`](#stop_playing) - - [Channel Function Reference](#channel_function_reference) + - [Channel Reference](#channel_reference) - [Constants](#constants) - [`WIDTH` & `HEIGHT`](#width--height) - [Using Breakouts](#using-breakouts) @@ -226,7 +226,7 @@ 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. -### `void clear()` +### `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. @@ -250,7 +250,7 @@ Start the synth playing. Stops any currently playing audio. -### Channel Function Reference +### Channel Reference ```python configure(waveforms=None, frequency=None, volume=None, From 408d105e8bd60f1f36b82bdaf6b7bf17f83073cb Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Fri, 4 Nov 2022 11:13:57 +0000 Subject: [PATCH 18/19] Link fixes --- micropython/modules/galactic_unicorn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/modules/galactic_unicorn/README.md b/micropython/modules/galactic_unicorn/README.md index 9a31dd25..9807ecf6 100644 --- a/micropython/modules/galactic_unicorn/README.md +++ b/micropython/modules/galactic_unicorn/README.md @@ -39,7 +39,7 @@ Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/ - [`synth_channel(channel)`](#synth_channelchannel) - [`play_synth()`](#play_synth) - [`stop_playing()`](#stop_playing) - - [Channel Reference](#channel_reference) + - [Channel Reference](#channel-reference) - [Constants](#constants) - [`WIDTH` & `HEIGHT`](#width--height) - [Using Breakouts](#using-breakouts) From 64b1a8c2d551cd4a11966a1d80e561c27bf300d4 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Fri, 4 Nov 2022 11:27:56 +0000 Subject: [PATCH 19/19] Additions to PicoGraphics readme for GU --- micropython/modules/picographics/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/micropython/modules/picographics/README.md b/micropython/modules/picographics/README.md index b86b1e7d..716909bb 100644 --- a/micropython/modules/picographics/README.md +++ b/micropython/modules/picographics/README.md @@ -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) @@ -63,6 +63,7 @@ Bear in mind that MicroPython has only 192K of RAM available- a 320x240 pixel di * 128x128 I2C OLED - `DISPLAY_I2C_OLED_128X128` * Pico Inky Pack - 296x128 mono e-ink - `DISPLAY_INKY_PACK` * Inky Frame - 600x447 7-colour e-ink - `DISPLAY_INKY_FRAME` +* Galactic Unicorn - 53x11 LED Matrix - `DISPLAY_GALACTIC_UNICORN` ### Supported Graphics Modes (Pen Type) @@ -72,6 +73,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. @@ -135,7 +137,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: @@ -153,7 +155,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 @@ -242,6 +244,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