added bounce effect
This commit is contained in:
+34
-8
@@ -7,27 +7,53 @@
|
||||
|
||||
#define PIXEL_COUNT 30
|
||||
|
||||
#define WAVEGRID_DEPTH 5
|
||||
#define WAVEGRID_LEN PIXEL_COUNT*WAVEGRID_DEPTH
|
||||
static float wavegrid[WAVEGRID_LEN];
|
||||
|
||||
#define WAVE_DISSIPATION 0.011f
|
||||
|
||||
|
||||
static ws2812_rgb_t pixels[PIXEL_COUNT] = {};
|
||||
|
||||
static MeanBuf *mb;
|
||||
|
||||
void display_show(void)
|
||||
{
|
||||
for (int i = 0; i < PIXEL_COUNT; i++) {
|
||||
|
||||
// 0 1 2 3 #0+i
|
||||
// 7 6 5 4 #2-i-1
|
||||
// 8 9 A B #2+i
|
||||
// F E D C #
|
||||
// G I J K
|
||||
|
||||
float x = wavegrid[i] +
|
||||
wavegrid[PIXEL_COUNT*2-i-1] +
|
||||
wavegrid[PIXEL_COUNT*2+i] +
|
||||
wavegrid[PIXEL_COUNT*4-i-1] +
|
||||
wavegrid[PIXEL_COUNT*4+i];
|
||||
|
||||
if (x > 255) x = 255;
|
||||
|
||||
pixels[i].r = (x);
|
||||
pixels[i].b = (255.0f-x);
|
||||
}
|
||||
|
||||
colorled_set_many((uint32_t*) pixels, PIXEL_COUNT);
|
||||
}
|
||||
|
||||
|
||||
static void handle_sonar_value(float mm)
|
||||
{
|
||||
for (int i = PIXEL_COUNT-1; i > 0; i--) {
|
||||
pixels[i].num = pixels[i-1].num;
|
||||
for (int i = WAVEGRID_LEN-1; i > 0; i--) {
|
||||
wavegrid[i] = wavegrid[i-1] * (1.0f - WAVE_DISSIPATION);
|
||||
}
|
||||
|
||||
float x = mm/5.0f;
|
||||
if (x>255) x = 255;
|
||||
|
||||
pixels[0].r = 255-x;
|
||||
pixels[0].b = x;
|
||||
wavegrid[0] = 255 - x;
|
||||
|
||||
display_show();
|
||||
}
|
||||
@@ -45,7 +71,7 @@ static void sonar(void* arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
info("Sonar");
|
||||
//info("Sonar");
|
||||
|
||||
GPIOB->BSRR = GPIO_Pin_13;
|
||||
delay_us(10);
|
||||
@@ -82,13 +108,13 @@ void display_init(void)
|
||||
{
|
||||
mb = meanbuf_create(10);
|
||||
|
||||
for (int i = 0; i < PIXEL_COUNT; i++) {
|
||||
pixels[i].num = rgb(0, 0, 255);
|
||||
for (int i = 0; i < WAVEGRID_LEN; i++) {
|
||||
wavegrid[i] = 0;
|
||||
}
|
||||
|
||||
display_show();
|
||||
|
||||
add_periodic_task(sonar, NULL, 50, true);
|
||||
|
||||
add_periodic_task(show, NULL, 50, true);
|
||||
add_periodic_task(show, NULL, 75, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user