Skip to content

Commit 9d96d06

Browse files
authored
Merge pull request #786 from pimoroni/feature/stellar_unicorn
16% More Unicorn
2 parents d460969 + 70a1b26 commit 9d96d06

File tree

100 files changed

+18096
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+18096
-77
lines changed

.github/workflows/micropython.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ jobs:
8686
board: PICO_W
8787
- name: cosmic_unicorn
8888
board: PICO_W
89+
- name: stellar_unicorn
90+
board: PICO_W
8991
- name: inky_frame
9092
board: PICO_W_INKY
9193
patch: true

common/pimoroni_common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace pimoroni {
7878
return to_ms_since_boot(get_absolute_time());
7979
}
8080

81-
constexpr uint8_t GAMMA_8BIT[256] = {
81+
inline constexpr uint8_t GAMMA_8BIT[256] = {
8282
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8383
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
8484
2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5,
@@ -98,7 +98,7 @@ namespace pimoroni {
9898

9999
/* Moved from pico_unicorn.cpp
100100
v = (uint16_t)(powf((float)(n) / 255.0f, 2.2) * 16383.0f + 0.5f) */
101-
constexpr uint16_t GAMMA_14BIT[256] = {
101+
inline constexpr uint16_t GAMMA_14BIT[256] = {
102102
0, 0, 0, 1, 2, 3, 4, 6, 8, 10, 13, 16, 20, 23, 28, 32,
103103
37, 42, 48, 54, 61, 67, 75, 82, 90, 99, 108, 117, 127, 137, 148, 159,
104104
170, 182, 195, 207, 221, 234, 249, 263, 278, 294, 310, 326, 343, 361, 379, 397,

drivers/analog/analog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace pimoroni {
1111
public:
1212
Analog(uint pin, float amplifier_gain = 1.0f, float resistor = 0.0f, float offset = 0.0f) :
1313
pin(pin), amplifier_gain(amplifier_gain), resistor(resistor), offset(offset) {
14-
adc_init();
14+
if (!(adc_hw->cs & ADC_CS_EN_BITS)) adc_init();
1515

1616
//Make sure GPIO is high-impedance, no pullups etc
1717
adc_gpio_init(pin);

drivers/rgbled/rgbled.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ target_sources(rgbled INTERFACE
77
target_include_directories(rgbled INTERFACE ${CMAKE_CURRENT_LIST_DIR})
88

99
# Pull in pico libraries that we need
10-
target_link_libraries(rgbled INTERFACE pico_stdlib hardware_pwm)
10+
target_link_libraries(rgbled INTERFACE pico_stdlib hardware_pwm)

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ add_subdirectory(encoder)
6161
add_subdirectory(galactic_unicorn)
6262
add_subdirectory(gfx_pack)
6363
add_subdirectory(cosmic_unicorn)
64+
add_subdirectory(stellar_unicorn)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
add_executable(
2+
stellar_rainbow_text
3+
stellar_rainbow_text.cpp
4+
)
5+
6+
# Pull in pico libraries that we need
7+
target_link_libraries(stellar_rainbow_text pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn)
8+
pico_enable_stdio_usb(stellar_rainbow_text 1)
9+
10+
# create map/bin/hex file etc.
11+
pico_add_extra_outputs(stellar_rainbow_text)
12+
13+
14+
15+
add_executable(
16+
stellar_rainbow
17+
stellar_rainbow.cpp
18+
)
19+
20+
# Pull in pico libraries that we need
21+
target_link_libraries(stellar_rainbow pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn)
22+
pico_enable_stdio_usb(stellar_rainbow 1)
23+
24+
# create map/bin/hex file etc.
25+
pico_add_extra_outputs(stellar_rainbow)
26+
27+
28+
29+
30+
add_executable(
31+
stellar_eighties_super_computer
32+
stellar_eighties_super_computer.cpp
33+
)
34+
35+
# Pull in pico libraries that we need
36+
target_link_libraries(stellar_eighties_super_computer pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn)
37+
pico_enable_stdio_usb(stellar_eighties_super_computer 1)
38+
39+
# create map/bin/hex file etc.
40+
pico_add_extra_outputs(stellar_eighties_super_computer)
41+
42+
43+
44+
45+
add_executable(
46+
stellar_fire_effect
47+
stellar_fire_effect.cpp
48+
)
49+
50+
# Pull in pico libraries that we need
51+
target_link_libraries(stellar_fire_effect pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn)
52+
pico_enable_stdio_usb(stellar_fire_effect 1)
53+
54+
# create map/bin/hex file etc.
55+
pico_add_extra_outputs(stellar_fire_effect)
56+
57+
58+
59+
60+
add_executable(
61+
stellar_scroll_text
62+
stellar_scroll_text.cpp
63+
)
64+
65+
# Pull in pico libraries that we need
66+
target_link_libraries(stellar_scroll_text pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn)
67+
pico_enable_stdio_usb(stellar_scroll_text 1)
68+
69+
# create map/bin/hex file etc.
70+
pico_add_extra_outputs(stellar_scroll_text)
71+
72+
73+
add_executable(
74+
stellar_lava_lamp
75+
stellar_lava_lamp.cpp
76+
)
77+
78+
# Pull in pico libraries that we need
79+
target_link_libraries(stellar_lava_lamp pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn)
80+
pico_enable_stdio_usb(stellar_lava_lamp 1)
81+
82+
# create map/bin/hex file etc.
83+
pico_add_extra_outputs(stellar_lava_lamp)
84+

examples/stellar_unicorn/audio_samples.cpp

Lines changed: 7847 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <math.h>
4+
#include "pico/stdlib.h"
5+
6+
#include "libraries/pico_graphics/pico_graphics.hpp"
7+
#include "stellar_unicorn.hpp"
8+
9+
using namespace pimoroni;
10+
11+
PicoGraphics_PenRGB888 graphics(16, 16, nullptr);
12+
StellarUnicorn stellar_unicorn;
13+
14+
float lifetime[16][16];
15+
float age[16][16];
16+
17+
int main() {
18+
19+
stdio_init_all();
20+
21+
for(int y = 0; y < 16; y++) {
22+
for(int x = 0; x < 16; x++) {
23+
lifetime[x][y] = 1.0f + ((rand() % 10) / 100.0f);
24+
age[x][y] = ((rand() % 100) / 100.0f) * lifetime[x][y];
25+
}
26+
}
27+
28+
stellar_unicorn.init();
29+
30+
while(true) {
31+
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_UP)) {
32+
stellar_unicorn.adjust_brightness(+0.01);
33+
}
34+
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_DOWN)) {
35+
stellar_unicorn.adjust_brightness(-0.01);
36+
}
37+
38+
graphics.set_pen(0, 0, 0);
39+
graphics.clear();
40+
41+
for(int y = 0; y < 16; y++) {
42+
for(int x = 0; x < 16; x++) {
43+
if(age[x][y] < lifetime[x][y] * 0.3f) {
44+
graphics.set_pen(230, 150, 0);
45+
graphics.pixel(Point(x, y));
46+
}else if(age[x][y] < lifetime[x][y] * 0.5f) {
47+
float decay = (lifetime[x][y] * 0.5f - age[x][y]) * 5.0f;
48+
graphics.set_pen(decay * 230, decay * 150, 0);
49+
graphics.pixel(Point(x, y));
50+
}
51+
52+
if(age[x][y] >= lifetime[x][y]) {
53+
age[x][y] = 0.0f;
54+
lifetime[x][y] = 1.0f + ((rand() % 10) / 100.0f);
55+
}
56+
57+
age[x][y] += 0.01f;
58+
}
59+
}
60+
61+
stellar_unicorn.update(&graphics);
62+
63+
sleep_ms(10);
64+
}
65+
66+
return 0;
67+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <math.h>
4+
#include <string.h>
5+
#include "pico/stdlib.h"
6+
7+
#include "libraries/pico_graphics/pico_graphics.hpp"
8+
#include "stellar_unicorn.hpp"
9+
10+
using namespace pimoroni;
11+
12+
PicoGraphics_PenRGB888 graphics(16, 16, nullptr);
13+
StellarUnicorn stellar_unicorn;
14+
15+
// extra row of pixels for sourcing flames and averaging
16+
int width = 16;
17+
int height = 17;
18+
19+
// a buffer that's at least big enough to store 55 x 15 values (to allow for both orientations)
20+
float heat[2000] = {0.0f};
21+
22+
void set(int x, int y, float v) {
23+
heat[x + y * width] = v;
24+
}
25+
26+
float get(int x, int y) {
27+
/*if(x < 0 || x >= width || y < 0 || y >= height) {
28+
return 0.0f;
29+
}*/
30+
x = x < 0 ? 0 : x;
31+
x = x >= width ? width - 1 : x;
32+
33+
return heat[x + y * width];
34+
}
35+
36+
int main() {
37+
38+
stdio_init_all();
39+
40+
stellar_unicorn.init();
41+
stellar_unicorn.set_brightness(0.2);
42+
43+
bool landscape = true;
44+
/*
45+
while(true) {
46+
stellar_unicorn.set_pixel(0, 0, 255, 0, 0);
47+
stellar_unicorn.set_pixel(1, 1, 0, 255, 0);
48+
stellar_unicorn.set_pixel(2, 2, 0, 0, 255);
49+
}*/
50+
51+
while(true) {
52+
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_UP)) {
53+
stellar_unicorn.adjust_brightness(+0.01);
54+
}
55+
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_DOWN)) {
56+
stellar_unicorn.adjust_brightness(-0.01);
57+
}
58+
59+
60+
for(int y = 0; y < height; y++) {
61+
for(int x = 0; x < width; x++) {
62+
float value = get(x, y);
63+
64+
graphics.set_pen(0, 0, 0);
65+
if(value > 0.5f) {
66+
graphics.set_pen(255, 255, 180);
67+
}else if(value > 0.4f) {
68+
graphics.set_pen(220, 160, 0);
69+
}else if(value > 0.3f) {
70+
graphics.set_pen(180, 30, 0);
71+
}else if(value > 0.22f) {
72+
graphics.set_pen(20, 20, 20);
73+
}
74+
75+
if(landscape) {
76+
graphics.pixel(Point(x, y));
77+
}else{
78+
graphics.pixel(Point(y, x));
79+
}
80+
81+
// update this pixel by averaging the below pixels
82+
float average = (get(x, y) + get(x, y + 2) + get(x, y + 1) + get(x - 1, y + 1) + get(x + 1, y + 1)) / 5.0f;
83+
84+
// damping factor to ensure flame tapers out towards the top of the displays
85+
average *= 0.95f;
86+
87+
// update the heat map with our newly averaged value
88+
set(x, y, average);
89+
}
90+
}
91+
92+
stellar_unicorn.update(&graphics);
93+
94+
// clear the bottom row and then add a new fire seed to it
95+
for(int x = 0; x < width; x++) {
96+
set(x, height - 1, 0.0f);
97+
}
98+
99+
// add a new random heat source
100+
int source_count = landscape ? 5 : 1;
101+
for(int c = 0; c < source_count; c++) {
102+
int px = (rand() % (width - 4)) + 2;
103+
set(px , height - 2, 1.0f);
104+
set(px + 1, height - 2, 1.0f);
105+
set(px - 1, height - 2, 1.0f);
106+
set(px , height - 1, 1.0f);
107+
set(px + 1, height - 1, 1.0f);
108+
set(px - 1, height - 1, 1.0f);
109+
}
110+
111+
sleep_ms(20);
112+
}
113+
114+
return 0;
115+
}

0 commit comments

Comments
 (0)