From 86c304d192afba0a08111e2c959538af130bab30 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 13:11:51 +0000 Subject: [PATCH 01/12] Cosmic - update remaining examples --- .../cosmic_unicorn/cheerlights_history.py | 4 ++-- .../examples/cosmic_unicorn/scrolling_text.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/micropython/examples/cosmic_unicorn/cheerlights_history.py b/micropython/examples/cosmic_unicorn/cheerlights_history.py index 6eb83cb50..72140a5cc 100644 --- a/micropython/examples/cosmic_unicorn/cheerlights_history.py +++ b/micropython/examples/cosmic_unicorn/cheerlights_history.py @@ -1,6 +1,6 @@ -# This Cosmic Unicorn example updates a pixel every five(ish) minutes +# This Cosmic Unicorn example updates a pixel every two(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! +# colours over time, or use it as an avant garde (but colourful) 32 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 diff --git a/micropython/examples/cosmic_unicorn/scrolling_text.py b/micropython/examples/cosmic_unicorn/scrolling_text.py index 40d8c7645..356861e3d 100644 --- a/micropython/examples/cosmic_unicorn/scrolling_text.py +++ b/micropython/examples/cosmic_unicorn/scrolling_text.py @@ -1,6 +1,6 @@ import time -from galactic import GalacticUnicorn -from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY +from cosmic import CosmicUnicorn +from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY ''' Display scrolling wisdom, quotes or greetz. @@ -17,12 +17,12 @@ HOLD_TIME = 2.0 STEP_TIME = 0.075 -# create galactic object and graphics surface for drawing -gu = GalacticUnicorn() +# create cosmic object and graphics surface for drawing +gu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) -width = GalacticUnicorn.WIDTH -height = GalacticUnicorn.HEIGHT +width = CosmicUnicorn.WIDTH +height = CosmicUnicorn.HEIGHT # function for drawing outlined text @@ -62,10 +62,10 @@ def outline_text(text, x, y): while True: time_ms = time.ticks_ms() - if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_UP): + if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): gu.adjust_brightness(+0.01) - if gu.is_pressed(GalacticUnicorn.SWITCH_BRIGHTNESS_DOWN): + if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): gu.adjust_brightness(-0.01) if state == STATE_PRE_SCROLL and time_ms - last_time > HOLD_TIME * 1000: From c2b1eb47e58a3ba24f5b9fd35a7f1450d9ef5958 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 13:17:57 +0000 Subject: [PATCH 02/12] Galactic - fix #661 --- .../examples/galactic_unicorn/feature_test_with_audio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/micropython/examples/galactic_unicorn/feature_test_with_audio.py b/micropython/examples/galactic_unicorn/feature_test_with_audio.py index 55af285c7..bc246ab2d 100644 --- a/micropython/examples/galactic_unicorn/feature_test_with_audio.py +++ b/micropython/examples/galactic_unicorn/feature_test_with_audio.py @@ -252,7 +252,7 @@ def tick(timer): was_c_pressed = False if gu.is_pressed(GalacticUnicorn.SWITCH_D): - if not was_c_pressed: + if not was_d_pressed: # Stop synth (if running) and play Tone B timer.deinit() tone_b = 600 @@ -291,7 +291,7 @@ def tick(timer): channels[0].frequency(tone_a) if gu.is_pressed(GalacticUnicorn.SWITCH_SLEEP): - if not was_d_pressed: + if not was_z_pressed: # Stop synth and both tones tone_a = 0 tone_b = 0 From 3e44edf66a5d6e72b546074ba54d0684cf040b4c Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 13:28:24 +0000 Subject: [PATCH 03/12] Galactic/Cosmic: fix #556 --- micropython/examples/cosmic_unicorn/clock.py | 5 ++--- micropython/examples/galactic_unicorn/clock.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/micropython/examples/cosmic_unicorn/clock.py b/micropython/examples/cosmic_unicorn/clock.py index 1272a41f6..994a87395 100644 --- a/micropython/examples/cosmic_unicorn/clock.py +++ b/micropython/examples/cosmic_unicorn/clock.py @@ -195,9 +195,6 @@ def redraw_display_if_reqd(): clock = "{:02}:{:02}:{:02}".format(hour, minute, second) - # set the font - graphics.set_font("bitmap8") - # calculate text position so that it is centred w = graphics.measure_text(clock, 1) x = int(width / 2 - w / 2 + 1) @@ -208,6 +205,8 @@ def redraw_display_if_reqd(): last_second = second +# set the font +graphics.set_font("bitmap8") gu.set_brightness(0.5) sync_time() diff --git a/micropython/examples/galactic_unicorn/clock.py b/micropython/examples/galactic_unicorn/clock.py index 13fce3331..b34f6da3a 100644 --- a/micropython/examples/galactic_unicorn/clock.py +++ b/micropython/examples/galactic_unicorn/clock.py @@ -195,9 +195,6 @@ def redraw_display_if_reqd(): clock = "{:02}:{:02}:{:02}".format(hour, minute, second) - # set the font - graphics.set_font("bitmap8") - # calculate text position so that it is centred w = graphics.measure_text(clock, 1) x = int(width / 2 - w / 2 + 1) @@ -208,6 +205,8 @@ def redraw_display_if_reqd(): last_second = second +# set the font +graphics.set_font("bitmap8") gu.set_brightness(0.5) sync_time() From c194fc7a2b68d46c5d26b83eeef577af8bbb4460 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 14:18:11 +0000 Subject: [PATCH 04/12] Cosmic: add examples readme --- micropython/examples/cosmic_unicorn/README.md | 89 ++++++++++++------- 1 file changed, 58 insertions(+), 31 deletions(-) diff --git a/micropython/examples/cosmic_unicorn/README.md b/micropython/examples/cosmic_unicorn/README.md index 7a635f0c8..fee016072 100644 --- a/micropython/examples/cosmic_unicorn/README.md +++ b/micropython/examples/cosmic_unicorn/README.md @@ -1,7 +1,7 @@ -# Galactic Unicorn MicroPython Examples +# Cosmic Unicorn MicroPython Examples -- [About Galactic Unicorn](#about-galactic-unicorn) -- [Galactic Unicorn and PicoGraphics](#galactic-unicorn-and-picographics) +- [About Cosmic Unicorn](#about-cosmic-unicorn) +- [Cosmic Unicorn and PicoGraphics](#cosmic-unicorn-and-picographics) - [Examples](#examples) - [Clock](#clock) - [Eighties Super Computer](#eighties-super-computer) @@ -12,29 +12,33 @@ - [Nostalgia Prompt](#nostalgia-prompt) - [Rainbow](#rainbow) - [Scrolling Text](#scrolling-text) + - [Today](#today) - [Wireless Examples](#wireless-examples) - [Cheerlights History](#cheerlights-history) - - [Galactic Paint](#galactic-paint) + - [Cosmic Paint](#cosmic-paint) + - [Exchange Ticker](#exchange-ticker) + - [HTTP Text](#http-text) + - [Weather](#weather) +- [Numpy examples](#numpy-examples) - [Other Examples](#other-examples) - [Launch (Demo Reel)](#launch-demo-reel) -- [Other Resources](#other-resources) -## About Galactic Unicorn +## About Cosmic 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! +Cosmic 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: [Cosmic Unicorn store page](https://shop.pimoroni.com/products/cosmic-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). +Cosmic Unicorn ships with MicroPython firmware pre-loaded, but you can download the most recent version at the link below (you'll want the `cosmic-unicorn` image). - [MicroPython releases](https://github.com/pimoroni/pimoroni-pico/releases) - [Installing MicroPython](../../../setting-up-micropython.md) -## Galactic Unicorn and PicoGraphics +## Cosmic 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. +The easiest way to start displaying cool stuff on Cosmic Unicorn is using our Cosmic 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) +- [Cosmic Unicorn function reference](../../modules/cosmic_unicorn/README.md) - [PicoGraphics function reference](../../modules/picographics/README.md) ## Examples @@ -98,9 +102,15 @@ Some good old fashioned rainbows! You can adjust the cycling speed with A and B, Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -. +### Today + +[today.py](today.py) + +Calendar example with (optional) NTP synchronization. You can adjust the brightness with LUX + and -, and resync the date by pressing C. + ## 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). +These examples need `WIFI_CONFIG.py` and `network_manager.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) @@ -108,35 +118,52 @@ These examples need `WIFI_CONFIG.py` (from the `common` directory) to be saved t [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/ +Updates one pixel every two minutes to display the most recent #Cheerlights colour. Discover the most popular colours over time, or use it as an avant garde (but colourful) 32 hour clock! Find out more about the Cheerlights API at https://cheerlights.com/ + +You can adjust the brightness with LUX + and -. + +### Cosmic Paint + +[cosmic_paint](cosmic_paint) + +Draw on your Cosmic Unicorn from another device in real time, over wifi! + +This example needs the `micropython-phew` and `microdot` libraries (you can install these using Thonny's 'Tools > Manage Packages'). + +### Exchange Ticker + +[exchange_ticker.py](exchange_ticker.py) -Requires `WIFI_CONFIG.py` and `network_manager.py` from the `common` directory. +This example uses the Coinbase open API to collect the current exchange rates of various cryptocurrencies. + +Press A to change to a different base exchange currency. + +### HTTP Text + +[http_text](http_text) + +Display scrolling wisdom, quotes or greetz... from another computer or device! You can adjust the brightness with LUX + and -. -### Galactic Paint +Requires `logging.mpy` and `tinyweb` from [micropython/examples/common](../../examples/common) - copy these into the `lib` folder on your Pico W. You'll also need `index.html` to be saved alongside `html_text.py`. -[galactic_paint](galactic_paint) +### Weather -Draw on your Galactic Unicorn from another device in real time, over wifi! +[weather](weather) -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'). +Display current weather data from the [Open-Meteo](https://open-meteo.com/) weather API. -## Other Examples +## Numpy examples -### Launch (Demo Reel) +[numpy](numpy) -[launch](launch) +The examples in the folder use `numpy` (part of the `ulab` library) for super fast graphical effects. -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. +## Other Examples -## Other Resources +### Launch (Demo Reel) -Here are some cool Galactic Unicorn community projects and resources that you might find useful / inspirational! Note that code at the links below has not been tested by us and we're not able to offer support with it. +[launch](launch) -- :link: [Galactic Unicorn MQTT scroller (and 3D printed case)](https://github.com/ucl-casa-ce/Galactic-Unicorn-MQTT-Scroller) -- :link: [Compiling custom pimoroni-pico MicroPython (with ulab)](https://medium.com/@iestynlloyd/galactic-unicorns-and-custom-pimoroni-pico-firmware-38dd7c5913b8) -- :link: [Galactic Unicorn Graphical Workout](https://www.instructables.com/Galactic-Unicorn-Graphical-Workout/) -- :link: [Galactic Unicorn Bounce - Simple GFX Demo](https://www.instructables.com/Galactic-Unicorn-Bounce-Simple-GFX-Demo/) -- :link: [Cheerlights + Galactic Unicorn + MicroPython (beginner-friendly tutorial)](https://cheerlights.com/cheerlights-raspberry-pi-pico-w-micropython/) -- :link: [CheerClock (plus laser-cut templates for a fancy case/diffuser)](https://github.com/seanosteen/CheerClock) \ No newline at end of file +If you want to get the demo reel that Cosmic Unicorn ships with back, copy the contents of this `launch` folder to your Pico W. \ No newline at end of file From b6042e78c18146541a1361adae131144a73f6f6e Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 14:27:31 +0000 Subject: [PATCH 05/12] Cosmic: update function reference --- micropython/modules/cosmic_unicorn/README.md | 82 ++++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/micropython/modules/cosmic_unicorn/README.md b/micropython/modules/cosmic_unicorn/README.md index 383d75e7f..2514d8cc9 100644 --- a/micropython/modules/cosmic_unicorn/README.md +++ b/micropython/modules/cosmic_unicorn/README.md @@ -1,12 +1,12 @@ -# Galactic Unicorn (MicroPython) +# Cosmic 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! +Cosmic Unicorn offers 32x32 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 +You can buy one here: https://shop.pimoroni.com/products/cosmic-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. +Internally Cosmic 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. @@ -14,9 +14,9 @@ No strobing or brightness stepping here folks - it's the perfect backdrop for yo ## Getting started -The Galactic Unicorn library provides a collection of methods that allow you to easily access all of the features on the board. +The Cosmic 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 Cosmic Unicorn to have it displayed on the screen. - [Example Program](#example-program) - [Interleaved Framebuffer](#interleaved-framebuffer) @@ -41,7 +41,7 @@ Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/ - [`stop_playing()`](#stop_playing) - [Channel Reference](#channel-reference) - [Constants](#constants) - - [`WIDTH` & `HEIGHT`](#width--height) + - [`WIDTH` \& `HEIGHT`](#width--height) - [Using Breakouts](#using-breakouts) # Example Program @@ -49,18 +49,18 @@ Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/ 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 +from cosmic import CosmicUnicorn +from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN import time # create a PicoGraphics framebuffer to draw into -graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN) +graphics = PicoGraphics(display=DISPLAY_COSMIC_UNICORN) -# create our GalacticUnicorn object -gu = GalacticUnicorn() +# create our CosmicUnicorn object +cu = CosmicUnicorn() # start position for scrolling (off the side of the display) -scroll = float(-GalacticUnicorn.WIDTH) +scroll = float(-CosmicUnicorn.WIDTH) # message to scroll MESSAGE = "Pirate. Monkey. Robot. Ninja." @@ -74,7 +74,7 @@ while True: width = graphics.measure_text(MESSAGE, 1) scroll += 0.25 if scroll > width: - scroll = float(-GalacticUnicorn.WIDTH) + scroll = float(-CosmicUnicorn.WIDTH) # clear the graphics object graphics.set_pen(BLACK) @@ -85,14 +85,14 @@ while True: graphics.text(MESSAGE, round(0 - scroll), 2, -1, 0.55); # update the display - gu.update(graphics) + cu.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. +Cosmic 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. @@ -116,22 +116,22 @@ If you're working with our library then you don't need to worry about any of the ## Imports and Objects -To access these functions, you'll need to first `import` the relevant libraries and then set up a Galactic Unicorn object: +To access these functions, you'll need to first `import` the relevant libraries and then set up a Cosmic Unicorn object: ```python -from galactic import GalacticUnicorn +from cosmic import CosmicUnicorn -gu = GalacticUnicorn() +cu = CosmicUnicorn() ``` or (with PicoGraphics): ```python -from galactic import GalacticUnicorn -from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN +from cosmic import CosmicUnicorn +from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN -gu = GalacticUnicorn() -graphics = PicoGraphics(display=DISPLAY_GALACTIC_UNICORN) +cu = CosmicUnicorn() +graphics = PicoGraphics(display=DISPLAY_COSMIC_UNICORN) ``` ## System State @@ -151,10 +151,10 @@ Adjust the brightness of the display - `delta` is supplied as a floating point v 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 +cu.set_brightness(0.5) +cu.adjust_brightness(0.1) # brightness is now 0.6 +cu.adjust_brightness(0.7) # brightness is now 1.0 +cu.adjust_brightness(-0.2) # brightness is now 0.8 ``` ### `set_volume(value)` @@ -172,10 +172,10 @@ Adjust the volume - `delta` is supplied as a floating point value and will be ad 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 +cu.set_volume(0.5) +cu.set_volume(0.1) # volume is now 0.6 +cu.adjust_volume(0.7) # volume is now 1.0 +cu.adjust_volume(-0.2) # volume is now 0.8 ``` ### `light()` @@ -186,7 +186,7 @@ Get the current value seen by the onboard light sensor as a value between `0` an 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: +There are a set of constants in the CosmicUnicorn 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 @@ -203,7 +203,7 @@ SWITCH_BRIGHTNESS_DOWN = 26 For example: ```python -while not gu.is_pressed(GalacticUnicorn.SWITCH_A): +while not cu.is_pressed(CosmicUnicorn.SWITCH_A): # wait for switch A to be pressed pass @@ -218,17 +218,17 @@ The PicoGraphics library provides a collection of powerful drawing methods to ma 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 Cosmic Unicorn and PicoGraphics objects up [as we did above](#imports-and-objects)): ```python -gu.update(graphics) +cu.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. +⚠️ If you've used PicoGraphics on our other boards note that this `update` function works a little differently. Here it's a Cosmic 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. +Clear the contents of the interleaved framebuffer. This will make your Cosmic Unicorn display turn off. To show an image again, call the `update()` function as described above. ## Audio @@ -282,22 +282,22 @@ play_tone(frequency, volume=None, attack=None, release=None) ### `WIDTH` & `HEIGHT` -The width and height of Galactic Unicorn are available in constants `WIDTH` and `HEIGHT`. +The width and height of Cosmic Unicorn are available in constants `WIDTH` and `HEIGHT`. For example: ```python -num_pixels = GalacticUnicorn.WIDTH * GalacticUnicorn.HEIGHT +num_pixels = CosmicUnicorn.WIDTH * CosmicUnicorn.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). +Cosmic 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: +Cosmic 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 6fc8ebd0244b82a88be937afd3b3380575c5369e Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 14:35:08 +0000 Subject: [PATCH 06/12] Cosmic: update C/C++ function reference --- libraries/cosmic_unicorn/README.md | 64 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/libraries/cosmic_unicorn/README.md b/libraries/cosmic_unicorn/README.md index 6d6eab90b..241bade84 100644 --- a/libraries/cosmic_unicorn/README.md +++ b/libraries/cosmic_unicorn/README.md @@ -1,12 +1,12 @@ -# Galactic Unicorn (C/C++) +# Cosmic 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! +Cosmic Unicorn offers 32x32 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 +You can buy one here: https://shop.pimoroni.com/products/cosmic-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. +Internally Cosmic 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. @@ -14,9 +14,9 @@ No strobing or brightness stepping here folks - it's the perfect backdrop for yo ## Getting started -The Galactic Unicorn library provides a collection of methods that allow you to easily access all of the features on the board. +The Cosmic 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/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. +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 Cosmic Unicorn to have it displayed on the screen. - [Example Program](#example-program) - [Interleaved Framebuffer](#interleaved-framebuffer) @@ -41,7 +41,7 @@ Drawing is primarily handled via our [PicoGraphics](https://github.com/pimoroni/ - [`void play_synth()`](#void-play_synth) - [`void stop_playing()`](#void-stop_playing) - [Constants](#constants) - - [`WIDTH` & `HEIGHT`](#width--height) + - [`WIDTH` \& `HEIGHT`](#width--height) # Example Program @@ -52,15 +52,15 @@ The following example shows how to scroll a simple message across the display. #include #include "libraries/pico_graphics/pico_graphics.hpp" -#include "galactic_unicorn.hpp" +#include "cosmic_unicorn.hpp" using namespace pimoroni; // create a PicoGraphics framebuffer to draw into -PicoGraphics_PenRGB888 graphics(GalacticUnicorn::WIDTH, GalacticUnicorn::HEIGHT, nullptr); +PicoGraphics_PenRGB888 graphics(CosmicUnicorn::WIDTH, CosmicUnicorn::HEIGHT, nullptr); -// create our GalacticUnicorn object -GalacticUnicorn galactic_unicorn; +// create our CosmicUnicorn object +CosmicUnicorn cosmic_unicorn; // message to scroll std::string message = "Pirate. Monkey. Robot. Ninja."; @@ -69,18 +69,18 @@ int main() { stdio_init_all(); - // initialise the GalacticUnicorn object - galactic_unicorn.init(); + // initialise the CosmicUnicorn object + cosmic_unicorn.init(); // start position for scrolling (off the side of the display) - float scroll = -(float)GalacticUnicorn::WIDTH; + float scroll = -(float)CosmicUnicorn::WIDTH; while(true) { // determine the scroll position of the text int width = graphics.measure_text(message, 1); scroll += 0.25f; if(scroll > width) { - scroll = -(float)GalacticUnicorn::WIDTH; + scroll = -(float)CosmicUnicorn::WIDTH; } // clear the graphics object @@ -92,7 +92,7 @@ int main() { graphics.text(message, Point(0 - scroll, 5), -1, 0.55); // update the display - galactic_unicorn.update(&graphics); + cosmic_unicorn.update(&graphics); sleep_ms(10); } @@ -103,7 +103,7 @@ int main() { # 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. +Cosmic 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. @@ -129,7 +129,7 @@ If you're working with our library then you don't need to worry about any of the ### `void init()` -Initialise the Galactic Unicorn hardware, interleaved framebuffer, and PIO programs. This function must be called before attempting to do anything else with Galactic Unicorn. +Initialise the Cosmic Unicorn hardware, interleaved framebuffer, and PIO programs. This function must be called before attempting to do anything else with Cosmic Unicorn. ### `void set_brightness(float value)` @@ -146,10 +146,10 @@ Adjust the brightness of the display - `delta` is supplied as a floating point v For example: ```c++ -galactic.set_brightness(0.5f); -galactic.adjust_brightness(0.1f); // brightness is now 0.6 -galactic.adjust_brightness(0.7f); // brightness is now 1.0 -galactic.adjust_brightness(-0.2f); // brightness is now 0.8 +cosmic.set_brightness(0.5f); +cosmic.adjust_brightness(0.1f); // brightness is now 0.6 +cosmic.adjust_brightness(0.7f); // brightness is now 1.0 +cosmic.adjust_brightness(-0.2f); // brightness is now 0.8 ``` ### `void set_volume(float value)` @@ -167,10 +167,10 @@ Adjust the volume - `delta` is supplied as a floating point value and will be ad For example: ```c++ -galactic.set_volume(0.5f); -galactic.adjust_volume(0.1f); // volume is now 0.6 -galactic.adjust_volume(0.7f); // volume is now 1.0 -galactic.adjust_volume(-0.2f); // volume is now 0.8 +cosmic.set_volume(0.5f); +cosmic.adjust_volume(0.1f); // volume is now 0.6 +cosmic.adjust_volume(0.7f); // volume is now 1.0 +cosmic.adjust_volume(-0.2f); // volume is now 0.8 ``` ### `uint16_t light()` @@ -181,7 +181,7 @@ Get the current value seen by the onboard light sensor as a value between `0` an Returns true if the requested `button` is currently pressed. -There are a set of constants on 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. +There are a set of constants on the CosmicUnicorn 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. ```c++ static const uint8_t SWITCH_A = 0; @@ -198,7 +198,7 @@ static const uint8_t SWITCH_BRIGHTNESS_DOWN = 26; For example: ```c++ -while(!galactic.is_pressed(GalacticUnicorn::SWITCH_A)) { +while(!cosmic.is_pressed(CosmicUnicorn::SWITCH_A)) { // wait for switch A to be pressed } printf("We did it! We pressed switch A! Heck yeah!"); @@ -208,7 +208,7 @@ printf("We did it! We pressed switch A! Heck yeah!"); ### `void update(PicoGraphics *graphics)` -**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. +**This is our recommended way to update the image on Cosmic 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. This lets you have multiple PicoGraphics objects on the go at once and switch between them by changing which gets passed into this function. @@ -216,7 +216,7 @@ If however you'd rather twiddle individual pixels (for example you're producing ### `void clear()` -Clear the contents of the interleaved framebuffer. This will make your Galactic Unicorn display turn off when the next frame is displayed. +Clear the contents of the interleaved framebuffer. This will make your Cosmic 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. @@ -250,10 +250,10 @@ Stops any currently playing audio. ### `WIDTH` & `HEIGHT` -The width and height of Galactic Unicorn are available in constants `WIDTH` and `HEIGHT`. +The width and height of Cosmic Unicorn are available in constants `WIDTH` and `HEIGHT`. For example: ```c++ -int num_pixels = GalacticUnicorn::WIDTH * GalacticUnicorn::HEIGHT; +int num_pixels = CosmicUnicorn::WIDTH * CosmicUnicorn::HEIGHT; ``` \ No newline at end of file From 931b3b26b201655297c3a57db43194fbd518ed7c Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 14:48:26 +0000 Subject: [PATCH 07/12] PicoGraphics: add note about HSV pen --- micropython/modules/picographics/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/micropython/modules/picographics/README.md b/micropython/modules/picographics/README.md index 76d227e2e..159bb9c8f 100644 --- a/micropython/modules/picographics/README.md +++ b/micropython/modules/picographics/README.md @@ -63,12 +63,13 @@ Bear in mind that MicroPython has only 192K of RAM available- a 320x240 pixel di * 240x240 Square SPI LCD Breakout - `DISPLAY_LCD_240X240` * 160x80 SPI LCD Breakout - `DISPLAY_LCD_160X80` * 128x128 I2C OLED - `DISPLAY_I2C_OLED_128X128` -* Pico Inky Pack - 296x128 mono E ink - `DISPLAY_INKY_PACK` +* Pico Inky Pack / Badger 2040 / Badger 2040 W - 296x128 mono E ink - `DISPLAY_INKY_PACK` * Inky Frame 5.7" - 600x448 7-colour E ink - `DISPLAY_INKY_FRAME` * Inky Frame 4.0" - 640x400 7-colour E ink - `DISPLAY_INKY_FRAME_4` * Pico GFX Pack - 128x64 mono LCD Matrix - `DISPLAY_GFX_PACK` * Galactic Unicorn - 53x11 LED Matrix - `DISPLAY_GALACTIC_UNICORN` * Interstate75 and 75W - HUB75 Matrix driver - `DISPLAY_INTERSTATE75_SIZEOFMATRIX` please read below! +* Cosmic Unicorn - 32x32 LED Matrix - `DISPLAY_COSMIC_UNICORN` #### Interstate75 and Interstate75W Display modes @@ -177,6 +178,12 @@ display.set_pen(my_pen) This will be either an RGB332, RGB565 or RGB888 colour, or a palette index. +As of v1.19.14 you can also specify an HSV pen, which allows a pen to be created from HSV (Hue, Saturation, Value) values, avoiding the need to calculate the RGB result in Python. + +```python +display.set_pen_hsv(h, s, v) +``` + ##### Monochrome Modes For 1BIT mode - such as for Inky Pack and the Mono OLED - pens are handled a little differently. From 7b8b2796edbb13c8a4eb18ad3d8fc98664c70056 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 15:01:20 +0000 Subject: [PATCH 08/12] Cosmic: tweak generic docs --- README.md | 3 ++- setting-up-micropython.md | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6bbddf74..108ac18a8 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,11 @@ We also maintain a C++/CMake boilerplate with GitHub workflows configured for te * 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 +* Galactic Unicorn (53 x 11 LED matrix) - https://shop.pimoroni.com/products/galactic-unicorn * Interstate 75 W (HUB75 matrix driver) - https://shop.pimoroni.com/products/interstate-75-w * Inky Frame 4.0" (7-colour E Ink) - https://shop.pimoroni.com/products/inky-frame-4 * Badger 2040 W (E Ink badge) - https://shop.pimoroni.com/products/badger-2040-w +* Cosmic Unicorn (32 x 32 LED matrix) - https://shop.pimoroni.com/products/cosmic-unicorn ## Breakouts diff --git a/setting-up-micropython.md b/setting-up-micropython.md index 3c9bfe72c..2d74ddc9c 100644 --- a/setting-up-micropython.md +++ b/setting-up-micropython.md @@ -28,6 +28,7 @@ On the releases page you'll find a bunch of different .uf2 files for use on diff | Galactic Unicorn | **pimoroni-picow_galactic_unicorn-vx.x.x-micropython.uf2** | | | Inky Frame | **pimoroni-picow_inky_frame-vx.x.x-micropython.uf2** | | | Badger 2040 W | **pimoroni-badger2040w-vx.x.x-micropython.uf2** or **pimoroni-badger2040w-vx.x.x-micropython-with-examples.uf2** | Download **pimoroni-badger2040w-vx.x.x-micropython-with-examples.uf2** for built in examples! | +| Cosmic Unicorn | **pimoroni-picow_cosmic_unicorn-vx.x.x-micropython.uf2** | | ## Entering DFU/bootloader mode From 3459cc5f62ac5bae4620e3628ccf6debd217bcf5 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 15:08:26 +0000 Subject: [PATCH 09/12] Cosmic: update clock example --- micropython/examples/cosmic_unicorn/clock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/cosmic_unicorn/clock.py b/micropython/examples/cosmic_unicorn/clock.py index 994a87395..80a8173f8 100644 --- a/micropython/examples/cosmic_unicorn/clock.py +++ b/micropython/examples/cosmic_unicorn/clock.py @@ -37,7 +37,7 @@ MIDNIGHT_VALUE = 0.3 -# create galactic object and graphics surface for drawing +# create cosmic object and graphics surface for drawing gu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) From 8069ae0e8f85cc41378bdd5b7c3081a190e0e8b3 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 15:43:38 +0000 Subject: [PATCH 10/12] Cosmic: make examples consistent --- .../cosmic_unicorn/cheerlights_history.py | 18 +++---- micropython/examples/cosmic_unicorn/clock.py | 18 +++---- .../cosmic_unicorn/eighties_super_computer.py | 14 ++--- .../examples/cosmic_unicorn/feature_test.py | 32 +++++------ .../cosmic_unicorn/feature_test_with_audio.py | 54 +++++++++---------- .../examples/cosmic_unicorn/fire_effect.py | 14 ++--- .../examples/cosmic_unicorn/lava_lamp.py | 16 +++--- .../cosmic_unicorn/nostalgia_prompt.py | 14 ++--- .../cosmic_unicorn/numpy/fire_effect.py | 14 ++--- .../cosmic_unicorn/numpy/lava_lamp.py | 14 ++--- .../cosmic_unicorn/numpy/the_matrix.py | 14 ++--- .../cosmic_unicorn/numpy/this_is_fine.py | 14 ++--- .../examples/cosmic_unicorn/numpy/trippy.py | 14 ++--- .../examples/cosmic_unicorn/rainbow.py | 28 +++++----- .../examples/cosmic_unicorn/scrolling_text.py | 14 ++--- micropython/examples/cosmic_unicorn/today.py | 16 +++--- 16 files changed, 154 insertions(+), 154 deletions(-) diff --git a/micropython/examples/cosmic_unicorn/cheerlights_history.py b/micropython/examples/cosmic_unicorn/cheerlights_history.py index 72140a5cc..eea833697 100644 --- a/micropython/examples/cosmic_unicorn/cheerlights_history.py +++ b/micropython/examples/cosmic_unicorn/cheerlights_history.py @@ -77,17 +77,17 @@ def update_leds(): graphics.set_pen(current_colour) graphics.pixel(x, y) i = i + 1 - gu.update(graphics) + cu.update(graphics) print("LEDs updated!") -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) width = CosmicUnicorn.WIDTH height = CosmicUnicorn.HEIGHT -gu.set_brightness(0.5) +cu.set_brightness(0.5) # set up the Pico W's onboard LED pico_led = Pin('LED', Pin.OUT) @@ -114,15 +114,15 @@ def update_leds(): 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(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.1) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.1) update_leds() - print(f"Brightness set to {gu.get_brightness()}") + print(f"Brightness set to {cu.get_brightness()}") - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.1) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.1) update_leds() - print(f"Brightness set to {gu.get_brightness()}") + print(f"Brightness set to {cu.get_brightness()}") # pause for a moment (important or the USB serial device will fail) time.sleep(0.001) diff --git a/micropython/examples/cosmic_unicorn/clock.py b/micropython/examples/cosmic_unicorn/clock.py index 80a8173f8..2c51ed091 100644 --- a/micropython/examples/cosmic_unicorn/clock.py +++ b/micropython/examples/cosmic_unicorn/clock.py @@ -38,7 +38,7 @@ # create cosmic object and graphics surface for drawing -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) # create the rtc object @@ -131,7 +131,7 @@ def sync_time(): time.sleep(0.2) redraw_display_if_reqd() - gu.update(graphics) + cu.update(graphics) if max_wait > 0: print("Connected") @@ -207,23 +207,23 @@ def redraw_display_if_reqd(): # set the font graphics.set_font("bitmap8") -gu.set_brightness(0.5) +cu.set_brightness(0.5) sync_time() while True: - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_A): + if cu.is_pressed(CosmicUnicorn.SWITCH_A): sync_time() redraw_display_if_reqd() # update the display - gu.update(graphics) + cu.update(graphics) time.sleep(0.01) diff --git a/micropython/examples/cosmic_unicorn/eighties_super_computer.py b/micropython/examples/cosmic_unicorn/eighties_super_computer.py index f51733a3c..725980ed4 100644 --- a/micropython/examples/cosmic_unicorn/eighties_super_computer.py +++ b/micropython/examples/cosmic_unicorn/eighties_super_computer.py @@ -10,7 +10,7 @@ You can adjust the brightness with LUX + and -. ''' -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) colour = (230, 150, 0) @@ -42,7 +42,7 @@ def draw(): graphics.set_pen(0) graphics.pixel(x, y) - gu.update(graphics) + cu.update(graphics) @micropython.native # noqa: F821 @@ -58,15 +58,15 @@ def update(): setup() -gu.set_brightness(0.5) +cu.set_brightness(0.5) while True: - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) start = time.ticks_ms() diff --git a/micropython/examples/cosmic_unicorn/feature_test.py b/micropython/examples/cosmic_unicorn/feature_test.py index 96758c46c..3ba5d0ab7 100644 --- a/micropython/examples/cosmic_unicorn/feature_test.py +++ b/micropython/examples/cosmic_unicorn/feature_test.py @@ -9,7 +9,7 @@ You can adjust the brightness with LUX + and -. ''' -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) width = CosmicUnicorn.WIDTH @@ -57,18 +57,18 @@ def outline_text(text): graphics.text(text, x, y, -1, 1) -gu.set_brightness(0.5) +cu.set_brightness(0.5) while True: time_ms = time.ticks_ms() test = (time_ms // 1000) % 5 - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) graphics.set_pen(graphics.create_pen(0, 0, 0)) graphics.clear() @@ -91,33 +91,33 @@ def outline_text(text): text = "" - if gu.is_pressed(CosmicUnicorn.SWITCH_A): + if cu.is_pressed(CosmicUnicorn.SWITCH_A): text = "Button A" - if gu.is_pressed(CosmicUnicorn.SWITCH_B): + if cu.is_pressed(CosmicUnicorn.SWITCH_B): text = "Button B" - if gu.is_pressed(CosmicUnicorn.SWITCH_C): + if cu.is_pressed(CosmicUnicorn.SWITCH_C): text = "Button C" - if gu.is_pressed(CosmicUnicorn.SWITCH_D): + if cu.is_pressed(CosmicUnicorn.SWITCH_D): text = "Button D" - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): text = "Louder!" - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): text = "Quieter" - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): text = "Brighter!" - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): text = "Darker" - if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): + if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): text = "Zzz... zzz..." outline_text(text) - gu.update(graphics) + cu.update(graphics) diff --git a/micropython/examples/cosmic_unicorn/feature_test_with_audio.py b/micropython/examples/cosmic_unicorn/feature_test_with_audio.py index a1a9bd15d..fdb89c6f8 100644 --- a/micropython/examples/cosmic_unicorn/feature_test_with_audio.py +++ b/micropython/examples/cosmic_unicorn/feature_test_with_audio.py @@ -18,7 +18,7 @@ gc.collect() -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) width = CosmicUnicorn.WIDTH @@ -56,7 +56,7 @@ SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, SUB, -1, SUB, -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0) notes = [melody_notes, rhythm_notes, drum_beats, hi_hat, bass_notes] -channels = [gu.synth_channel(i) for i in range(len(notes) + 1)] # Extra channel for tones +channels = [cu.synth_channel(i) for i in range(len(notes) + 1)] # Extra channel for tones # Configure the synth to play our notes channels[0].configure(waveforms=Channel.TRIANGLE + Channel.SQUARE, @@ -136,7 +136,7 @@ def outline_text(text): graphics.text(text, x, y, -1, 1) -gu.set_brightness(0.5) +cu.set_brightness(0.5) # Vars for storing button state was_a_pressed = False @@ -181,7 +181,7 @@ def tick(timer): time_ms = time.ticks_ms() test = (time_ms // 1000) % 5 - if gu.is_pressed(CosmicUnicorn.SWITCH_A): + if cu.is_pressed(CosmicUnicorn.SWITCH_A): if not was_a_pressed: channels[0].volume(10000 / 65535) channels[1].volume(12000 / 65535) @@ -195,7 +195,7 @@ def tick(timer): beat = 0 next_beat() - gu.play_synth() + cu.play_synth() synthing = True timer.init(freq=10, mode=Timer.PERIODIC, callback=tick) @@ -203,7 +203,7 @@ def tick(timer): else: was_a_pressed = False - if gu.is_pressed(CosmicUnicorn.SWITCH_B): + if cu.is_pressed(CosmicUnicorn.SWITCH_B): if not was_b_pressed: channels[0].volume(0) channels[1].volume(12000 / 65535) @@ -217,7 +217,7 @@ def tick(timer): beat = 0 next_beat() - gu.play_synth() + cu.play_synth() synthing = True timer.init(freq=10, mode=Timer.PERIODIC, callback=tick) @@ -225,7 +225,7 @@ def tick(timer): else: was_b_pressed = False - if gu.is_pressed(CosmicUnicorn.SWITCH_C): + if cu.is_pressed(CosmicUnicorn.SWITCH_C): if not was_c_pressed: # Stop synth (if running) and play Tone A timer.deinit() @@ -233,14 +233,14 @@ def tick(timer): channels[5].play_tone(tone_a, 0.06) channels[5].volume(12000 / 65535) - gu.play_synth() + cu.play_synth() synthing = False was_c_pressed = True else: was_c_pressed = False - if gu.is_pressed(CosmicUnicorn.SWITCH_D): + if cu.is_pressed(CosmicUnicorn.SWITCH_D): if not was_d_pressed: # Stop synth (if running) and play Tone B timer.deinit() @@ -249,43 +249,43 @@ def tick(timer): channels[5].play_tone(tone_b, 0.06, attack=0.5) channels[5].volume(12000 / 65535) - gu.play_synth() + cu.play_synth() synthing = False was_d_pressed = True else: was_d_pressed = False - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): if tone_b > 0: # Zero means tone not playing # Increase Tone B tone_b = min(tone_b + 10, 20000) channels[5].frequency(tone_b) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): if tone_b > 0: # Zero means tone not playing # Decrease Tone B tone_b = max(tone_b - 10, 10) channels[5].frequency(max(tone_b, 10)) - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): if tone_a > 0: # Zero means tone not playing # Increase Tone A tone_a = min(tone_a + 10, 20000) channels[5].frequency(tone_a) - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): if tone_a > 0: # Zero means tone not playing # Decrease Tone A tone_a = max(tone_a - 10, 10) channels[5].frequency(tone_a) - if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): + if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): if not was_z_pressed: # Stop synth and both tones tone_a = 0 tone_b = 0 - gu.stop_playing() + cu.stop_playing() timer.deinit() synthing = False @@ -312,36 +312,36 @@ def tick(timer): # print("white gradient") gradient(255, 255, 255) - if gu.is_pressed(CosmicUnicorn.SWITCH_A): + if cu.is_pressed(CosmicUnicorn.SWITCH_A): text = "PlaySyn" - if gu.is_pressed(CosmicUnicorn.SWITCH_B): + if cu.is_pressed(CosmicUnicorn.SWITCH_B): text = "SoloSyn" - if gu.is_pressed(CosmicUnicorn.SWITCH_C): + if cu.is_pressed(CosmicUnicorn.SWITCH_C): text = "Tone A" - if gu.is_pressed(CosmicUnicorn.SWITCH_D): + if cu.is_pressed(CosmicUnicorn.SWITCH_D): text = "Tone B" - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): text = "RaiseA" - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): text = "LowerA" - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): text = "RaiseB" - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): text = "LowerB" - if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): + if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): text = "Stop" outline_text(text) - gu.update(graphics) + cu.update(graphics) # pause for a moment (important or the USB serial device will fail time.sleep(0.001) diff --git a/micropython/examples/cosmic_unicorn/fire_effect.py b/micropython/examples/cosmic_unicorn/fire_effect.py index 14d60929d..510c49952 100644 --- a/micropython/examples/cosmic_unicorn/fire_effect.py +++ b/micropython/examples/cosmic_unicorn/fire_effect.py @@ -9,7 +9,7 @@ You can adjust the brightness with LUX + and -. ''' -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) fire_colours = [graphics.create_pen(0, 0, 0), @@ -71,7 +71,7 @@ def draw(): _set_pen(_fire_colours[4]) _pixel(x, y) - gu.update(_graphics) + cu.update(_graphics) width = CosmicUnicorn.WIDTH + 2 @@ -81,15 +81,15 @@ def draw(): damping_factor = 0.97 -gu.set_brightness(0.5) +cu.set_brightness(0.5) while True: - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) start = time.ticks_ms() diff --git a/micropython/examples/cosmic_unicorn/lava_lamp.py b/micropython/examples/cosmic_unicorn/lava_lamp.py index e0c7fafc4..853d58e11 100644 --- a/micropython/examples/cosmic_unicorn/lava_lamp.py +++ b/micropython/examples/cosmic_unicorn/lava_lamp.py @@ -10,7 +10,7 @@ You can adjust the brightness with LUX + and -. ''' -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) blob_count = 10 @@ -121,22 +121,22 @@ def draw_portrait(): graphics.set_pen(0) graphics.pixel(y, x) - gu.update(graphics) + cu.update(graphics) setup_portrait() -gu.set_brightness(0.5) +cu.set_brightness(0.5) while True: - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_A): + if cu.is_pressed(CosmicUnicorn.SWITCH_A): setup_portrait() start = time.ticks_ms() diff --git a/micropython/examples/cosmic_unicorn/nostalgia_prompt.py b/micropython/examples/cosmic_unicorn/nostalgia_prompt.py index 363d91383..21080fac9 100644 --- a/micropython/examples/cosmic_unicorn/nostalgia_prompt.py +++ b/micropython/examples/cosmic_unicorn/nostalgia_prompt.py @@ -9,7 +9,7 @@ You can adjust the brightness with LUX + and -. ''' -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) prompt_x = 0 @@ -125,21 +125,21 @@ def draw(image, fg, bg, time_ms): graphics.pixel(x + prompt_x, y + prompt_y) - gu.update(graphics) + cu.update(graphics) -gu.set_brightness(0.5) +cu.set_brightness(0.5) while True: time_ms = time.ticks_ms() prompt = (time_ms // 3000) % 3 - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) start = time.ticks_ms() diff --git a/micropython/examples/cosmic_unicorn/numpy/fire_effect.py b/micropython/examples/cosmic_unicorn/numpy/fire_effect.py index bf3804847..76cd5db79 100644 --- a/micropython/examples/cosmic_unicorn/numpy/fire_effect.py +++ b/micropython/examples/cosmic_unicorn/numpy/fire_effect.py @@ -13,8 +13,8 @@ # MAXIMUM OVERKILL # machine.freq(250_000_000) -gu = CosmicUnicorn() -gu.set_brightness(0.5) +cu = CosmicUnicorn() +cu.set_brightness(0.5) graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8) # Number of random fire spawns @@ -79,7 +79,7 @@ def draw(): # Multiplies it by the number of palette entries (-1) to turn it into a palette index # Converts to uint8_t datatype to match the framebuffer memoryview(graphics)[:] = numpy.ndarray(numpy.clip(heat[0:32, 0:32], 0, 1) * (PALETTE_SIZE - 1), dtype=numpy.uint8).tobytes() - gu.update(graphics) + cu.update(graphics) width = CosmicUnicorn.WIDTH @@ -92,11 +92,11 @@ def draw(): while True: gc.collect() - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) tstart = time.ticks_ms() gc.collect() diff --git a/micropython/examples/cosmic_unicorn/numpy/lava_lamp.py b/micropython/examples/cosmic_unicorn/numpy/lava_lamp.py index 3e5b4665f..2058c18ed 100644 --- a/micropython/examples/cosmic_unicorn/numpy/lava_lamp.py +++ b/micropython/examples/cosmic_unicorn/numpy/lava_lamp.py @@ -13,9 +13,9 @@ # MAXIMUM OVERKILL # machine.freq(250_000_000) -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8) -gu.set_brightness(0.5) +cu.set_brightness(0.5) width = CosmicUnicorn.WIDTH height = CosmicUnicorn.HEIGHT @@ -77,18 +77,18 @@ def draw(): # Multiplies by palette entries (-1) to turn it into a palette index # Converts to uint8_t datatype to match the framebuffer memoryview(graphics)[:] = numpy.ndarray(numpy.clip(lava, 0.0, 1.0) * (PAL_COLS - 1), dtype=numpy.uint8).tobytes() - gu.update(graphics) + cu.update(graphics) t_count = 0 t_total = 0 while True: - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) tstart = time.ticks_ms() gc.collect() diff --git a/micropython/examples/cosmic_unicorn/numpy/the_matrix.py b/micropython/examples/cosmic_unicorn/numpy/the_matrix.py index bf41e71d2..c8c0dc694 100644 --- a/micropython/examples/cosmic_unicorn/numpy/the_matrix.py +++ b/micropython/examples/cosmic_unicorn/numpy/the_matrix.py @@ -12,8 +12,8 @@ # MAXIMUM OVERKILL # machine.freq(250_000_000) -gu = CosmicUnicorn() -gu.set_brightness(1.0) +cu = CosmicUnicorn() +cu.set_brightness(1.0) graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8) @@ -43,7 +43,7 @@ def update(): def draw(): # Copy the effect to the framebuffer memoryview(graphics)[:] = numpy.ndarray(numpy.clip(trippy, 0, 1) * 254, dtype=numpy.uint8).tobytes() - gu.update(graphics) + cu.update(graphics) width = CosmicUnicorn.WIDTH @@ -55,11 +55,11 @@ def draw(): while True: - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) tstart = time.ticks_ms() gc.collect() diff --git a/micropython/examples/cosmic_unicorn/numpy/this_is_fine.py b/micropython/examples/cosmic_unicorn/numpy/this_is_fine.py index 2a367151c..9d64b5fa7 100644 --- a/micropython/examples/cosmic_unicorn/numpy/this_is_fine.py +++ b/micropython/examples/cosmic_unicorn/numpy/this_is_fine.py @@ -12,8 +12,8 @@ # MAXIMUM OVERKILL # machine.freq(250_000_000) -gu = CosmicUnicorn() -gu.set_brightness(0.5) +cu = CosmicUnicorn() +cu.set_brightness(0.5) graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8) # Number of random fire spawns @@ -84,7 +84,7 @@ def draw(): graphics.text("This", 6, 4, 1, 1) graphics.text("is", 11, 12, 1, 1) graphics.text("fine", 6, 20, 1, 1) - gu.update(graphics) + cu.update(graphics) width = CosmicUnicorn.WIDTH @@ -97,11 +97,11 @@ def draw(): while True: gc.collect() - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) tstart = time.ticks_ms() gc.collect() diff --git a/micropython/examples/cosmic_unicorn/numpy/trippy.py b/micropython/examples/cosmic_unicorn/numpy/trippy.py index 1f1ff102f..2d1de0f4a 100644 --- a/micropython/examples/cosmic_unicorn/numpy/trippy.py +++ b/micropython/examples/cosmic_unicorn/numpy/trippy.py @@ -13,8 +13,8 @@ # MAXIMUM OVERKILL # machine.freq(250_000_000) -gu = CosmicUnicorn() -gu.set_brightness(0.5) +cu = CosmicUnicorn() +cu.set_brightness(0.5) graphics = PicoGraphics(DISPLAY_COSMIC_UNICORN, pen_type=PEN_P8) @@ -51,7 +51,7 @@ def update(): def draw(): # Copy the effect to the framebuffer memoryview(graphics)[:] = numpy.ndarray(numpy.clip(trippy, 0, 1) * (PALETTE_ENTRIES - 1), dtype=numpy.uint8).tobytes() - gu.update(graphics) + cu.update(graphics) width = CosmicUnicorn.WIDTH @@ -63,11 +63,11 @@ def draw(): while True: - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) tstart = time.ticks_ms() gc.collect() diff --git a/micropython/examples/cosmic_unicorn/rainbow.py b/micropython/examples/cosmic_unicorn/rainbow.py index 2bcdca6dc..021c989ab 100644 --- a/micropython/examples/cosmic_unicorn/rainbow.py +++ b/micropython/examples/cosmic_unicorn/rainbow.py @@ -12,7 +12,7 @@ The sleep button stops the animation (can be started again with A or B). ''' -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) width = CosmicUnicorn.WIDTH @@ -55,7 +55,7 @@ def draw(): graphics.set_pen(graphics.create_pen(int(colour[0] * v), int(colour[1] * v), int(colour[2] * v))) graphics.pixel(x, y) - gu.update(graphics) + cu.update(graphics) hue_map = [from_hsv(x / width, 1.0, 1.0) for x in range(width)] @@ -65,7 +65,7 @@ def draw(): stripe_width = 3.0 speed = 1.0 -gu.set_brightness(0.5) +cu.set_brightness(0.5) phase = 0 while True: @@ -73,38 +73,38 @@ def draw(): if animate: phase += speed - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_UP): hue_offset += 0.01 hue_offset = 1.0 if hue_offset > 1.0 else hue_offset - if gu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): + if cu.is_pressed(CosmicUnicorn.SWITCH_VOLUME_DOWN): hue_offset -= 0.01 hue_offset = 0.0 if hue_offset < 0.0 else hue_offset - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): + if cu.is_pressed(CosmicUnicorn.SWITCH_SLEEP): animate = False - if gu.is_pressed(CosmicUnicorn.SWITCH_A): + if cu.is_pressed(CosmicUnicorn.SWITCH_A): speed += 0.05 speed = 10.0 if speed > 10.0 else speed animate = True - if gu.is_pressed(CosmicUnicorn.SWITCH_B): + if cu.is_pressed(CosmicUnicorn.SWITCH_B): speed -= 0.05 speed = 0.0 if speed < 0.0 else speed animate = True - if gu.is_pressed(CosmicUnicorn.SWITCH_C): + if cu.is_pressed(CosmicUnicorn.SWITCH_C): stripe_width += 0.05 stripe_width = 10.0 if stripe_width > 10.0 else stripe_width - if gu.is_pressed(CosmicUnicorn.SWITCH_D): + if cu.is_pressed(CosmicUnicorn.SWITCH_D): stripe_width -= 0.05 stripe_width = 1.0 if stripe_width < 1.0 else stripe_width diff --git a/micropython/examples/cosmic_unicorn/scrolling_text.py b/micropython/examples/cosmic_unicorn/scrolling_text.py index 356861e3d..80c591c1a 100644 --- a/micropython/examples/cosmic_unicorn/scrolling_text.py +++ b/micropython/examples/cosmic_unicorn/scrolling_text.py @@ -18,7 +18,7 @@ STEP_TIME = 0.075 # create cosmic object and graphics surface for drawing -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) width = CosmicUnicorn.WIDTH @@ -41,7 +41,7 @@ def outline_text(text, x, y): graphics.text(text, x, y, -1, 1) -gu.set_brightness(0.5) +cu.set_brightness(0.5) # state constants STATE_PRE_SCROLL = 0 @@ -62,11 +62,11 @@ def outline_text(text, x, y): while True: time_ms = time.ticks_ms() - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) if state == STATE_PRE_SCROLL and time_ms - last_time > HOLD_TIME * 1000: if msg_width + PADDING * 2 >= width: @@ -90,7 +90,7 @@ def outline_text(text, x, y): outline_text(MESSAGE, x=PADDING - shift, y=2) # update the display - gu.update(graphics) + cu.update(graphics) # pause for a moment (important or the USB serial device will fail) time.sleep(0.001) diff --git a/micropython/examples/cosmic_unicorn/today.py b/micropython/examples/cosmic_unicorn/today.py index 7b03aa5cd..15f7694d8 100644 --- a/micropython/examples/cosmic_unicorn/today.py +++ b/micropython/examples/cosmic_unicorn/today.py @@ -6,11 +6,11 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -gu = CosmicUnicorn() +cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) # Default Brightness -gu.set_brightness(0.4) +cu.set_brightness(0.4) # You will need to create or update the file secrets.py with your network credentials using Thonny # in order for the example to update using the NTP. @@ -106,7 +106,7 @@ def draw(): graphics.set_pen(graphics.create_pen(0, 0, 0)) - gu.update(graphics) + cu.update(graphics) init() @@ -114,14 +114,14 @@ def draw(): while 1: # Adjust Brightness +/- - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): - gu.adjust_brightness(+0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_UP): + cu.adjust_brightness(+0.01) - if gu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): - gu.adjust_brightness(-0.01) + if cu.is_pressed(CosmicUnicorn.SWITCH_BRIGHTNESS_DOWN): + cu.adjust_brightness(-0.01) # Connect to the network and sync with the NTP server - if gu.is_pressed(CosmicUnicorn.SWITCH_C): + if cu.is_pressed(CosmicUnicorn.SWITCH_C): sync_time() draw() From 6aa5aaf50cc496993563fd4228dc277c9530b852 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 16:01:37 +0000 Subject: [PATCH 11/12] Cosmic: update examples readme --- micropython/examples/cosmic_unicorn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/cosmic_unicorn/README.md b/micropython/examples/cosmic_unicorn/README.md index fee016072..29b9415d4 100644 --- a/micropython/examples/cosmic_unicorn/README.md +++ b/micropython/examples/cosmic_unicorn/README.md @@ -25,7 +25,7 @@ ## About Cosmic Unicorn -Cosmic 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! +Cosmic Unicorn offers 32x32 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: [Cosmic Unicorn store page](https://shop.pimoroni.com/products/cosmic-unicorn) From ec601de9a4943db67f327551051a9920e35cae66 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Mon, 27 Feb 2023 16:47:08 +0000 Subject: [PATCH 12/12] Cosmic: Update examples readme --- micropython/examples/cosmic_unicorn/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython/examples/cosmic_unicorn/README.md b/micropython/examples/cosmic_unicorn/README.md index 29b9415d4..66e483e92 100644 --- a/micropython/examples/cosmic_unicorn/README.md +++ b/micropython/examples/cosmic_unicorn/README.md @@ -19,7 +19,7 @@ - [Exchange Ticker](#exchange-ticker) - [HTTP Text](#http-text) - [Weather](#weather) -- [Numpy examples](#numpy-examples) +- [NumPy examples](#numpy-examples) - [Other Examples](#other-examples) - [Launch (Demo Reel)](#launch-demo-reel) @@ -154,11 +154,11 @@ Requires `logging.mpy` and `tinyweb` from [micropython/examples/common](../../ex Display current weather data from the [Open-Meteo](https://open-meteo.com/) weather API. -## Numpy examples +## NumPy examples [numpy](numpy) -The examples in the folder use `numpy` (part of the `ulab` library) for super fast graphical effects. +The examples in the folder use `numpy`-like array functions contained in the `ulab` library for super fast graphical effects. ## Other Examples