Skip to content

Commit 049219c

Browse files
authored
Merge pull request #641 from pimoroni/cosmic
Cosmic
2 parents 93ac854 + 2176e0f commit 049219c

File tree

68 files changed

+15325
-208
lines changed

Some content is hidden

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

68 files changed

+15325
-208
lines changed

.github/workflows/micropython-picow.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ jobs:
7272
board: PICO_W_ENVIRO
7373
- name: picow_galactic_unicorn
7474
board: PICO_W
75+
- name: picow_cosmic_unicorn
76+
board: PICO_W
7577
- name: picow_inky_frame
7678
board: PICO_W_INKY
7779

examples/CMakeLists.txt

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

examples/cosmic_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 "cosmic_unicorn.hpp"
8+
9+
using namespace pimoroni;
10+
11+
PicoGraphics_PenRGB888 graphics(32, 32, nullptr);
12+
CosmicUnicorn cosmic_unicorn;
13+
14+
float lifetime[32][32];
15+
float age[32][32];
16+
17+
int main() {
18+
19+
stdio_init_all();
20+
21+
for(int y = 0; y < 32; y++) {
22+
for(int x = 0; x < 32; 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+
cosmic_unicorn.init();
29+
30+
while(true) {
31+
if(cosmic_unicorn.is_pressed(cosmic_unicorn.SWITCH_BRIGHTNESS_UP)) {
32+
cosmic_unicorn.adjust_brightness(+0.01);
33+
}
34+
if(cosmic_unicorn.is_pressed(cosmic_unicorn.SWITCH_BRIGHTNESS_DOWN)) {
35+
cosmic_unicorn.adjust_brightness(-0.01);
36+
}
37+
38+
graphics.set_pen(0, 0, 0);
39+
graphics.clear();
40+
41+
for(int y = 0; y < 32; y++) {
42+
for(int x = 0; x < 32; 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+
cosmic_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 "cosmic_unicorn.hpp"
9+
10+
using namespace pimoroni;
11+
12+
PicoGraphics_PenRGB888 graphics(32, 32, nullptr);
13+
CosmicUnicorn cosmic_unicorn;
14+
15+
// extra row of pixels for sourcing flames and averaging
16+
int width = 32;
17+
int height = 33;
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+
cosmic_unicorn.init();
41+
cosmic_unicorn.set_brightness(0.2);
42+
43+
bool landscape = true;
44+
/*
45+
while(true) {
46+
cosmic_unicorn.set_pixel(0, 0, 255, 0, 0);
47+
cosmic_unicorn.set_pixel(1, 1, 0, 255, 0);
48+
cosmic_unicorn.set_pixel(2, 2, 0, 0, 255);
49+
}*/
50+
51+
while(true) {
52+
if(cosmic_unicorn.is_pressed(cosmic_unicorn.SWITCH_BRIGHTNESS_UP)) {
53+
cosmic_unicorn.adjust_brightness(+0.01);
54+
}
55+
if(cosmic_unicorn.is_pressed(cosmic_unicorn.SWITCH_BRIGHTNESS_DOWN)) {
56+
cosmic_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.98f;
86+
87+
// update the heat map with our newly averaged value
88+
set(x, y, average);
89+
}
90+
}
91+
92+
cosmic_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)