Add eerie and spooky animations
This commit is contained in:
parent
307617b1b2
commit
ca0847c73d
160
lantern/main.c
160
lantern/main.c
|
@ -20,16 +20,17 @@ You should have received a copy of the GNU General Public License along with thi
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define ANIMATION_FRAMES 5
|
#define FPS 15
|
||||||
#define FPS 15
|
#define FRAME_DELAY_MS 1000 / FPS
|
||||||
#define FRAME_DELAY_MS 1000 / FPS
|
|
||||||
// #define FRAME_DELAY_MS 1000
|
// #define FRAME_DELAY_MS 1000
|
||||||
#define LIGHT_COUNT 3
|
#define LIGHT_COUNT 3
|
||||||
|
#define PULSE_OFF_COUNT FPS * 5
|
||||||
|
#define PULSE_ON_COUNT 5
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
test,
|
test,
|
||||||
normal,
|
normal,
|
||||||
creepy,
|
spooky,
|
||||||
eerie,
|
eerie,
|
||||||
flash
|
flash
|
||||||
} color_scheme_e;
|
} color_scheme_e;
|
||||||
|
@ -44,17 +45,10 @@ uint8_t bound_uint8(int value, uint8_t min, uint8_t max) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t random_step(display_t *display, uint8_t value, uint8_t min, uint8_t max, rng_t *rng) {
|
uint8_t random_step(uint8_t value, uint8_t min, uint8_t max, rng_t *rng) {
|
||||||
// int8_t step = (rng_sample(rng) % 40) - 20;
|
|
||||||
int8_t step = (rand() % 40) - 20;
|
int8_t step = (rand() % 40) - 20;
|
||||||
int new_value = value + step;
|
int new_value = value + step;
|
||||||
|
|
||||||
// char msg[20];
|
|
||||||
// snprintf(msg, 20, "[%x] %x -> %x", step, value, new_value);
|
|
||||||
// display_clear(display);
|
|
||||||
// display_write_message(display, msg);
|
|
||||||
// _delay_ms(1000);
|
|
||||||
|
|
||||||
return bound_uint8(new_value, min, max);
|
return bound_uint8(new_value, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,40 +127,82 @@ void lantern_start_test(lantern_t *self) {
|
||||||
255,
|
255,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
ANIMATION_FRAMES);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[1],
|
&self->animations[1],
|
||||||
0,
|
0,
|
||||||
255,
|
255,
|
||||||
0,
|
0,
|
||||||
ANIMATION_FRAMES);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[2],
|
&self->animations[2],
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
255,
|
255,
|
||||||
ANIMATION_FRAMES);
|
5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lantern_start_normal(display_t *display, lantern_t *self, rng_t *rng) {
|
void lantern_start_normal(lantern_t *self, rng_t *rng) {
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[0],
|
&self->animations[0],
|
||||||
random_step(display, self->animations[0].color.r, 180, 255, rng),
|
random_step(self->animations[0].color.r, 180, 255, rng),
|
||||||
random_step(display, self->animations[0].color.g, 20, 50, rng),
|
random_step(self->animations[0].color.g, 20, 50, rng),
|
||||||
0,
|
0,
|
||||||
FPS);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[1],
|
&self->animations[1],
|
||||||
random_step(display, self->animations[1].color.r, 160, 230, rng),
|
random_step(self->animations[1].color.r, 160, 230, rng),
|
||||||
random_step(display, self->animations[1].color.g, 10, 30, rng),
|
random_step(self->animations[1].color.g, 10, 30, rng),
|
||||||
0,
|
0,
|
||||||
FPS);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[2],
|
&self->animations[2],
|
||||||
random_step(display, self->animations[2].color.r, 140, 170, rng),
|
random_step(self->animations[2].color.r, 140, 170, rng),
|
||||||
random_step(display, self->animations[2].color.g, 0, 10, rng),
|
random_step(self->animations[2].color.g, 0, 10, rng),
|
||||||
0,
|
0,
|
||||||
FPS);
|
5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lantern_start_spooky(lantern_t *self, rng_t *rng) {
|
||||||
|
animation_begin(
|
||||||
|
&self->animations[0],
|
||||||
|
0,
|
||||||
|
random_step(self->animations[0].color.g, 80, 120, rng),
|
||||||
|
0,
|
||||||
|
15);
|
||||||
|
animation_begin(
|
||||||
|
&self->animations[1],
|
||||||
|
0,
|
||||||
|
random_step(self->animations[1].color.g, 60, 100, rng),
|
||||||
|
0,
|
||||||
|
15);
|
||||||
|
animation_begin(
|
||||||
|
&self->animations[2],
|
||||||
|
0,
|
||||||
|
random_step(self->animations[2].color.g, 20, 40, rng),
|
||||||
|
0,
|
||||||
|
15);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lantern_start_eerie(lantern_t *self, rng_t *rng) {
|
||||||
|
animation_begin(
|
||||||
|
&self->animations[0],
|
||||||
|
random_step(self->animations[0].color.g, 20, 40, rng),
|
||||||
|
random_step(self->animations[0].color.g, 20, 40, rng),
|
||||||
|
random_step(self->animations[0].color.g, 80, 120, rng),
|
||||||
|
15);
|
||||||
|
animation_begin(
|
||||||
|
&self->animations[1],
|
||||||
|
random_step(self->animations[0].color.g, 0, 30, rng),
|
||||||
|
random_step(self->animations[0].color.g, 0, 30, rng),
|
||||||
|
random_step(self->animations[1].color.g, 60, 100, rng),
|
||||||
|
15);
|
||||||
|
animation_begin(
|
||||||
|
&self->animations[2],
|
||||||
|
random_step(self->animations[0].color.g, 0, 10, rng),
|
||||||
|
random_step(self->animations[0].color.g, 0, 10, rng),
|
||||||
|
random_step(self->animations[2].color.g, 20, 40, rng),
|
||||||
|
15);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lantern_set_mode(lantern_t *self, color_scheme_e scheme) {
|
void lantern_set_mode(lantern_t *self, color_scheme_e scheme) {
|
||||||
|
@ -181,11 +217,13 @@ void lantern_step(lantern_t *self, display_t *display, rng_t *rng, rgb_t colors[
|
||||||
lantern_start_test(self);
|
lantern_start_test(self);
|
||||||
break;
|
break;
|
||||||
case normal:
|
case normal:
|
||||||
lantern_start_normal(display, self, rng);
|
lantern_start_normal(self, rng);
|
||||||
break;
|
break;
|
||||||
case creepy:
|
case spooky:
|
||||||
|
lantern_start_spooky(self, rng);
|
||||||
break;
|
break;
|
||||||
case eerie:
|
case eerie:
|
||||||
|
lantern_start_eerie(self, rng);
|
||||||
break;
|
break;
|
||||||
case flash:
|
case flash:
|
||||||
break;
|
break;
|
||||||
|
@ -223,10 +261,18 @@ void display_lantern(display_t *display, lantern_t *lantern) {
|
||||||
display_write_message(display, msg2);
|
display_write_message(display, msg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool on;
|
||||||
|
int timeout;
|
||||||
|
} power_pulse_t;
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
dio_t status_light = { .ddr = &DDRC, .port = &PORTC, .pin = &PINC, .addr = 7 };
|
dio_t status_light = { .ddr = &DDRC, .port = &PORTC, .pin = &PINC, .addr = 7 };
|
||||||
dio_set_direction(&status_light, LINE_OUT);
|
dio_set_direction(&status_light, LINE_OUT);
|
||||||
|
|
||||||
|
dio_t power_pulse = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 0 };
|
||||||
|
dio_set_direction(&power_pulse, LINE_OUT);
|
||||||
|
|
||||||
display_t display = {
|
display_t display = {
|
||||||
.reg = {
|
.reg = {
|
||||||
.output = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 7 },
|
.output = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 7 },
|
||||||
|
@ -255,57 +301,35 @@ int main(void) {
|
||||||
rgb_t colors[LIGHT_COUNT];
|
rgb_t colors[LIGHT_COUNT];
|
||||||
|
|
||||||
lantern_t lantern = lantern_new(lights);
|
lantern_t lantern = lantern_new(lights);
|
||||||
lantern_set_mode(&lantern, normal);
|
lantern_set_mode(&lantern, eerie);
|
||||||
|
|
||||||
rng_t rng = rng_new(15);
|
rng_t rng = rng_new(15);
|
||||||
|
|
||||||
// display_clear(&display);
|
|
||||||
// display_write_message(&display, "ready");
|
|
||||||
|
|
||||||
// _delay_ms(5000);
|
|
||||||
|
|
||||||
lantern_step(&lantern, &display, &rng, colors);
|
lantern_step(&lantern, &display, &rng, colors);
|
||||||
sk9822_send(&lights, colors, LIGHT_COUNT);
|
sk9822_send(&lights, colors, LIGHT_COUNT);
|
||||||
|
|
||||||
|
power_pulse_t timer = { .on = false, .timeout = PULSE_OFF_COUNT };
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
lantern_step(&lantern, &display, &rng, colors);
|
lantern_step(&lantern, &display, &rng, colors);
|
||||||
sk9822_send(&lights, colors, LIGHT_COUNT);
|
sk9822_send(&lights, colors, LIGHT_COUNT);
|
||||||
|
|
||||||
|
if (timer.timeout > 0) {
|
||||||
|
timer.timeout--;
|
||||||
|
} else {
|
||||||
|
if (timer.on) {
|
||||||
|
timer.on = false;
|
||||||
|
dio_set(&power_pulse, 0);
|
||||||
|
timer.timeout = PULSE_OFF_COUNT;
|
||||||
|
} else {
|
||||||
|
timer.on = true;
|
||||||
|
dio_set(&power_pulse, 1);
|
||||||
|
timer.timeout = PULSE_ON_COUNT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_delay_ms(FRAME_DELAY_MS);
|
_delay_ms(FRAME_DELAY_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
rgb_t colors[3] = {
|
|
||||||
{ .brightness = 1, .r = 128, .g = 0, .b = 0, },
|
|
||||||
{ .brightness = 1, .r = 0, .g = 128, .b = 0, },
|
|
||||||
{ .brightness = 1, .r = 0, .g = 0, .b = 128, },
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
sk9822_init(&lights);
|
|
||||||
sk9822_send(&lights, colors, 3);
|
|
||||||
|
|
||||||
int flash_recovery = 0;
|
|
||||||
|
|
||||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (flash_recovery == 0) {
|
|
||||||
uint8_t value = dio_read(&buttons[0]);
|
|
||||||
if (value != 0) {
|
|
||||||
flash_status(&status_light);
|
|
||||||
flash_recovery = 128;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
colors[0] = (rgb_t){ .brightness = bound(flash_recovery / 4, 1, 31), .r = 128 + flash_recovery, .g = flash_recovery * 2, .b = flash_recovery * 2 },
|
|
||||||
colors[1] = (rgb_t){ .brightness = bound(flash_recovery / 4, 1, 31), .r = flash_recovery * 2, .g = 128 + flash_recovery, .b = flash_recovery * 2 },
|
|
||||||
colors[2] = (rgb_t){ .brightness = bound(flash_recovery / 4, 1, 31), .r = flash_recovery * 2, .g = flash_recovery * 2, .b = 128 + flash_recovery },
|
|
||||||
sk9822_send(&lights, colors, 3);
|
|
||||||
flash_recovery -= 2;
|
|
||||||
}
|
|
||||||
_delay_ms(ANIMATION_DELAY);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue