-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C++ examples for Stellar, and fix init
- Loading branch information
1 parent
68f6101
commit 7aa75e5
Showing
10 changed files
with
8,640 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
add_executable( | ||
stellar_rainbow_text | ||
stellar_rainbow_text.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(stellar_rainbow_text pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn) | ||
pico_enable_stdio_usb(stellar_rainbow_text 1) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(stellar_rainbow_text) | ||
|
||
|
||
|
||
add_executable( | ||
stellar_rainbow | ||
stellar_rainbow.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(stellar_rainbow pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn) | ||
pico_enable_stdio_usb(stellar_rainbow 1) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(stellar_rainbow) | ||
|
||
|
||
|
||
|
||
add_executable( | ||
stellar_eighties_super_computer | ||
stellar_eighties_super_computer.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(stellar_eighties_super_computer pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn) | ||
pico_enable_stdio_usb(stellar_eighties_super_computer 1) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(stellar_eighties_super_computer) | ||
|
||
|
||
|
||
|
||
add_executable( | ||
stellar_fire_effect | ||
stellar_fire_effect.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(stellar_fire_effect pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn) | ||
pico_enable_stdio_usb(stellar_fire_effect 1) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(stellar_fire_effect) | ||
|
||
|
||
|
||
|
||
add_executable( | ||
stellar_scroll_text | ||
stellar_scroll_text.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(stellar_scroll_text pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn) | ||
pico_enable_stdio_usb(stellar_scroll_text 1) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(stellar_scroll_text) | ||
|
||
|
||
add_executable( | ||
stellar_lava_lamp | ||
stellar_lava_lamp.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(stellar_lava_lamp pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics stellar_unicorn) | ||
pico_enable_stdio_usb(stellar_lava_lamp 1) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(stellar_lava_lamp) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
examples/stellar_unicorn/stellar_eighties_super_computer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include "pico/stdlib.h" | ||
|
||
#include "libraries/pico_graphics/pico_graphics.hpp" | ||
#include "stellar_unicorn.hpp" | ||
|
||
using namespace pimoroni; | ||
|
||
PicoGraphics_PenRGB888 graphics(16, 16, nullptr); | ||
StellarUnicorn stellar_unicorn; | ||
|
||
float lifetime[16][16]; | ||
float age[16][16]; | ||
|
||
int main() { | ||
|
||
stdio_init_all(); | ||
|
||
for(int y = 0; y < 16; y++) { | ||
for(int x = 0; x < 16; x++) { | ||
lifetime[x][y] = 1.0f + ((rand() % 10) / 100.0f); | ||
age[x][y] = ((rand() % 100) / 100.0f) * lifetime[x][y]; | ||
} | ||
} | ||
|
||
stellar_unicorn.init(); | ||
|
||
while(true) { | ||
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_UP)) { | ||
stellar_unicorn.adjust_brightness(+0.01); | ||
} | ||
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_DOWN)) { | ||
stellar_unicorn.adjust_brightness(-0.01); | ||
} | ||
|
||
graphics.set_pen(0, 0, 0); | ||
graphics.clear(); | ||
|
||
for(int y = 0; y < 16; y++) { | ||
for(int x = 0; x < 16; x++) { | ||
if(age[x][y] < lifetime[x][y] * 0.3f) { | ||
graphics.set_pen(230, 150, 0); | ||
graphics.pixel(Point(x, y)); | ||
}else if(age[x][y] < lifetime[x][y] * 0.5f) { | ||
float decay = (lifetime[x][y] * 0.5f - age[x][y]) * 5.0f; | ||
graphics.set_pen(decay * 230, decay * 150, 0); | ||
graphics.pixel(Point(x, y)); | ||
} | ||
|
||
if(age[x][y] >= lifetime[x][y]) { | ||
age[x][y] = 0.0f; | ||
lifetime[x][y] = 1.0f + ((rand() % 10) / 100.0f); | ||
} | ||
|
||
age[x][y] += 0.01f; | ||
} | ||
} | ||
|
||
stellar_unicorn.update(&graphics); | ||
|
||
sleep_ms(10); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include <string.h> | ||
#include "pico/stdlib.h" | ||
|
||
#include "libraries/pico_graphics/pico_graphics.hpp" | ||
#include "stellar_unicorn.hpp" | ||
|
||
using namespace pimoroni; | ||
|
||
PicoGraphics_PenRGB888 graphics(16, 16, nullptr); | ||
StellarUnicorn stellar_unicorn; | ||
|
||
// extra row of pixels for sourcing flames and averaging | ||
int width = 16; | ||
int height = 17; | ||
|
||
// a buffer that's at least big enough to store 55 x 15 values (to allow for both orientations) | ||
float heat[2000] = {0.0f}; | ||
|
||
void set(int x, int y, float v) { | ||
heat[x + y * width] = v; | ||
} | ||
|
||
float get(int x, int y) { | ||
/*if(x < 0 || x >= width || y < 0 || y >= height) { | ||
return 0.0f; | ||
}*/ | ||
x = x < 0 ? 0 : x; | ||
x = x >= width ? width - 1 : x; | ||
|
||
return heat[x + y * width]; | ||
} | ||
|
||
int main() { | ||
|
||
stdio_init_all(); | ||
|
||
stellar_unicorn.init(); | ||
stellar_unicorn.set_brightness(0.2); | ||
|
||
bool landscape = true; | ||
/* | ||
while(true) { | ||
stellar_unicorn.set_pixel(0, 0, 255, 0, 0); | ||
stellar_unicorn.set_pixel(1, 1, 0, 255, 0); | ||
stellar_unicorn.set_pixel(2, 2, 0, 0, 255); | ||
}*/ | ||
|
||
while(true) { | ||
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_UP)) { | ||
stellar_unicorn.adjust_brightness(+0.01); | ||
} | ||
if(stellar_unicorn.is_pressed(stellar_unicorn.SWITCH_BRIGHTNESS_DOWN)) { | ||
stellar_unicorn.adjust_brightness(-0.01); | ||
} | ||
|
||
|
||
for(int y = 0; y < height; y++) { | ||
for(int x = 0; x < width; x++) { | ||
float value = get(x, y); | ||
|
||
graphics.set_pen(0, 0, 0); | ||
if(value > 0.5f) { | ||
graphics.set_pen(255, 255, 180); | ||
}else if(value > 0.4f) { | ||
graphics.set_pen(220, 160, 0); | ||
}else if(value > 0.3f) { | ||
graphics.set_pen(180, 30, 0); | ||
}else if(value > 0.22f) { | ||
graphics.set_pen(20, 20, 20); | ||
} | ||
|
||
if(landscape) { | ||
graphics.pixel(Point(x, y)); | ||
}else{ | ||
graphics.pixel(Point(y, x)); | ||
} | ||
|
||
// update this pixel by averaging the below pixels | ||
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; | ||
|
||
// damping factor to ensure flame tapers out towards the top of the displays | ||
average *= 0.95f; | ||
|
||
// update the heat map with our newly averaged value | ||
set(x, y, average); | ||
} | ||
} | ||
|
||
stellar_unicorn.update(&graphics); | ||
|
||
// clear the bottom row and then add a new fire seed to it | ||
for(int x = 0; x < width; x++) { | ||
set(x, height - 1, 0.0f); | ||
} | ||
|
||
// add a new random heat source | ||
int source_count = landscape ? 5 : 1; | ||
for(int c = 0; c < source_count; c++) { | ||
int px = (rand() % (width - 4)) + 2; | ||
set(px , height - 2, 1.0f); | ||
set(px + 1, height - 2, 1.0f); | ||
set(px - 1, height - 2, 1.0f); | ||
set(px , height - 1, 1.0f); | ||
set(px + 1, height - 1, 1.0f); | ||
set(px - 1, height - 1, 1.0f); | ||
} | ||
|
||
sleep_ms(20); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.