Added all lights, all animations, and the trigger buttons
This commit is contained in:
parent
bdbb13f67f
commit
11436eeb28
|
@ -1,14 +1,9 @@
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef __ANIMATION_H__
|
#ifndef __ANIMATION_H__
|
||||||
#define __ANIMATION_H__
|
#define __ANIMATION_H__
|
||||||
|
|
||||||
#ifdef __AVR__
|
|
||||||
#include <avr/io.h>
|
|
||||||
#else
|
|
||||||
|
|
||||||
typedef int uint8_t;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// line_t provides a simplified implementation of Bresenham's line drawing
|
// line_t provides a simplified implementation of Bresenham's line drawing
|
||||||
// technique. At this time, it assumes a transition of x = 0 -> 60, and a dy
|
// technique. At this time, it assumes a transition of x = 0 -> 60, and a dy
|
||||||
// between -59 and 59. I am not sure I understand Bresenham's algorithm yet,
|
// between -59 and 59. I am not sure I understand Bresenham's algorithm yet,
|
||||||
|
|
|
@ -3,11 +3,11 @@ Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
This file is part of Savanni's AVR library.
|
This file is part of Savanni's AVR library.
|
||||||
|
|
||||||
Lumeto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
This AVR library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
Lumeto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
This AVR library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this AVR library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BASE_H__
|
#ifndef __BASE_H__
|
||||||
|
|
|
@ -114,19 +114,19 @@ void lantern_start_normal(lantern_t *self, int light_idx) {
|
||||||
random_step(self->animations[1].color.r, 160, 230),
|
random_step(self->animations[1].color.r, 160, 230),
|
||||||
random_step(self->animations[1].color.g, 10, 30),
|
random_step(self->animations[1].color.g, 10, 30),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[4],
|
&self->animations[4],
|
||||||
random_step(self->animations[4].color.r, 160, 230),
|
random_step(self->animations[4].color.r, 160, 230),
|
||||||
random_step(self->animations[4].color.g, 10, 30),
|
random_step(self->animations[4].color.g, 10, 30),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[7],
|
&self->animations[7],
|
||||||
random_step(self->animations[7].color.r, 160, 230),
|
random_step(self->animations[7].color.r, 160, 230),
|
||||||
random_step(self->animations[7].color.g, 10, 30),
|
random_step(self->animations[7].color.g, 10, 30),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
animation_begin(
|
animation_begin(
|
||||||
|
@ -134,19 +134,19 @@ void lantern_start_normal(lantern_t *self, int light_idx) {
|
||||||
random_step(self->animations[2].color.r, 140, 170),
|
random_step(self->animations[2].color.r, 140, 170),
|
||||||
random_step(self->animations[2].color.g, 0, 10),
|
random_step(self->animations[2].color.g, 0, 10),
|
||||||
0,
|
0,
|
||||||
30);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[5],
|
&self->animations[5],
|
||||||
random_step(self->animations[5].color.r, 140, 170),
|
random_step(self->animations[5].color.r, 140, 170),
|
||||||
random_step(self->animations[5].color.g, 0, 10),
|
random_step(self->animations[5].color.g, 0, 10),
|
||||||
0,
|
0,
|
||||||
30);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[8],
|
&self->animations[8],
|
||||||
random_step(self->animations[8].color.r, 140, 170),
|
random_step(self->animations[8].color.r, 140, 170),
|
||||||
random_step(self->animations[8].color.g, 0, 10),
|
random_step(self->animations[8].color.g, 0, 10),
|
||||||
0,
|
0,
|
||||||
30);
|
5);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,19 +159,19 @@ void lantern_start_spooky(lantern_t *self, int light_idx) {
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[0].color.g, 80, 120),
|
random_step(self->animations[0].color.g, 80, 120),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[3],
|
&self->animations[3],
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[3].color.g, 80, 120),
|
random_step(self->animations[3].color.g, 80, 120),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[6],
|
&self->animations[6],
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[6].color.g, 80, 120),
|
random_step(self->animations[6].color.g, 80, 120),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
animation_begin(
|
animation_begin(
|
||||||
|
@ -179,19 +179,19 @@ void lantern_start_spooky(lantern_t *self, int light_idx) {
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[1].color.g, 60, 100),
|
random_step(self->animations[1].color.g, 60, 100),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[4],
|
&self->animations[4],
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[4].color.g, 60, 100),
|
random_step(self->animations[4].color.g, 60, 100),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[7],
|
&self->animations[7],
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[7].color.g, 60, 100),
|
random_step(self->animations[7].color.g, 60, 100),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
animation_begin(
|
animation_begin(
|
||||||
|
@ -199,19 +199,19 @@ void lantern_start_spooky(lantern_t *self, int light_idx) {
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[2].color.g, 20, 40),
|
random_step(self->animations[2].color.g, 20, 40),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[5],
|
&self->animations[5],
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[5].color.g, 20, 40),
|
random_step(self->animations[5].color.g, 20, 40),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[8],
|
&self->animations[8],
|
||||||
0,
|
0,
|
||||||
random_step(self->animations[8].color.g, 20, 40),
|
random_step(self->animations[8].color.g, 20, 40),
|
||||||
0,
|
0,
|
||||||
15);
|
5);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,19 +224,19 @@ void lantern_start_eerie(lantern_t *self, int light_idx) {
|
||||||
random_step(self->animations[0].color.r, 20, 40),
|
random_step(self->animations[0].color.r, 20, 40),
|
||||||
random_step(self->animations[0].color.g, 20, 40),
|
random_step(self->animations[0].color.g, 20, 40),
|
||||||
random_step(self->animations[0].color.b, 80, 120),
|
random_step(self->animations[0].color.b, 80, 120),
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[3],
|
&self->animations[3],
|
||||||
random_step(self->animations[3].color.r, 20, 40),
|
random_step(self->animations[3].color.r, 20, 40),
|
||||||
random_step(self->animations[3].color.g, 20, 40),
|
random_step(self->animations[3].color.g, 20, 40),
|
||||||
random_step(self->animations[3].color.b, 80, 120),
|
random_step(self->animations[3].color.b, 80, 120),
|
||||||
15);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[6],
|
&self->animations[6],
|
||||||
random_step(self->animations[6].color.r, 20, 40),
|
random_step(self->animations[6].color.r, 20, 40),
|
||||||
random_step(self->animations[6].color.g, 20, 40),
|
random_step(self->animations[6].color.g, 20, 40),
|
||||||
random_step(self->animations[6].color.b, 80, 120),
|
random_step(self->animations[6].color.b, 80, 120),
|
||||||
15);
|
5);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
animation_begin(
|
animation_begin(
|
||||||
|
@ -244,19 +244,19 @@ void lantern_start_eerie(lantern_t *self, int light_idx) {
|
||||||
random_step(self->animations[1].color.r, 0, 30),
|
random_step(self->animations[1].color.r, 0, 30),
|
||||||
random_step(self->animations[1].color.g, 0, 30),
|
random_step(self->animations[1].color.g, 0, 30),
|
||||||
random_step(self->animations[1].color.b, 60, 100),
|
random_step(self->animations[1].color.b, 60, 100),
|
||||||
30);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[4],
|
&self->animations[4],
|
||||||
random_step(self->animations[4].color.r, 0, 30),
|
random_step(self->animations[4].color.r, 0, 30),
|
||||||
random_step(self->animations[4].color.g, 0, 30),
|
random_step(self->animations[4].color.g, 0, 30),
|
||||||
random_step(self->animations[4].color.b, 60, 100),
|
random_step(self->animations[4].color.b, 60, 100),
|
||||||
30);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[7],
|
&self->animations[7],
|
||||||
random_step(self->animations[7].color.r, 0, 30),
|
random_step(self->animations[7].color.r, 0, 30),
|
||||||
random_step(self->animations[7].color.g, 0, 30),
|
random_step(self->animations[7].color.g, 0, 30),
|
||||||
random_step(self->animations[7].color.b, 60, 100),
|
random_step(self->animations[7].color.b, 60, 100),
|
||||||
30);
|
5);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
animation_begin(
|
animation_begin(
|
||||||
|
@ -264,19 +264,19 @@ void lantern_start_eerie(lantern_t *self, int light_idx) {
|
||||||
random_step(self->animations[2].color.r, 0, 10),
|
random_step(self->animations[2].color.r, 0, 10),
|
||||||
random_step(self->animations[2].color.g, 0, 10),
|
random_step(self->animations[2].color.g, 0, 10),
|
||||||
random_step(self->animations[2].color.b, 20, 40),
|
random_step(self->animations[2].color.b, 20, 40),
|
||||||
45);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[5],
|
&self->animations[5],
|
||||||
random_step(self->animations[5].color.r, 0, 10),
|
random_step(self->animations[5].color.r, 0, 10),
|
||||||
random_step(self->animations[5].color.g, 0, 10),
|
random_step(self->animations[5].color.g, 0, 10),
|
||||||
random_step(self->animations[5].color.b, 20, 40),
|
random_step(self->animations[5].color.b, 20, 40),
|
||||||
45);
|
5);
|
||||||
animation_begin(
|
animation_begin(
|
||||||
&self->animations[8],
|
&self->animations[8],
|
||||||
random_step(self->animations[8].color.r, 0, 10),
|
random_step(self->animations[8].color.r, 0, 10),
|
||||||
random_step(self->animations[8].color.g, 0, 10),
|
random_step(self->animations[8].color.g, 0, 10),
|
||||||
random_step(self->animations[8].color.b, 20, 40),
|
random_step(self->animations[8].color.b, 20, 40),
|
||||||
45);
|
5);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,6 +308,7 @@ void lantern_step(lantern_t *self, rgb_t colors[LIGHT_COUNT]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void lantern_show(lantern_t *lantern, display_t *display) {
|
void lantern_show(lantern_t *lantern, display_t *display) {
|
||||||
char msg1[20];
|
char msg1[20];
|
||||||
char msg2[20];
|
char msg2[20];
|
||||||
|
@ -332,5 +333,5 @@ void lantern_show(lantern_t *lantern, display_t *display) {
|
||||||
display_set_location(display, 1, 0);
|
display_set_location(display, 1, 0);
|
||||||
display_write_message(display, msg2);
|
display_write_message(display, msg2);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,11 @@ You should have received a copy of the GNU General Public License along with thi
|
||||||
#include <avr/sleep.h>
|
#include <avr/sleep.h>
|
||||||
#include <dio.h>
|
#include <dio.h>
|
||||||
#include <display.h>
|
#include <display.h>
|
||||||
|
#include "lantern.h"
|
||||||
#include <sk9822.h>
|
#include <sk9822.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "lantern.h"
|
|
||||||
|
|
||||||
#define FPS 15
|
#define FPS 15
|
||||||
#define TICKS_PER_SECOND 7812
|
#define TICKS_PER_SECOND 7812
|
||||||
|
@ -29,11 +29,28 @@ You should have received a copy of the GNU General Public License along with thi
|
||||||
uint8_t status_light_value = 0;
|
uint8_t status_light_value = 0;
|
||||||
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_t buttons[4] = {
|
||||||
|
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 },
|
||||||
|
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 6 },
|
||||||
|
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 },
|
||||||
|
{ .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 6 },
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int button_press[4];
|
||||||
|
bool frame_timeout;
|
||||||
|
} status_flags_t;
|
||||||
|
|
||||||
|
status_flags_t status_flags;
|
||||||
|
|
||||||
ISR(TIMER1_COMPA_vect) {
|
ISR(TIMER1_COMPA_vect) {
|
||||||
/*
|
status_flags.frame_timeout = true;
|
||||||
status_light_value = !status_light_value;
|
}
|
||||||
dio_set(&status_light, status_light_value);
|
|
||||||
*/
|
ISR(INT2_vect) {
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
status_flags.button_press[i] = dio_read(&buttons[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -56,6 +73,14 @@ void setup_fps_timer(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
EIMSK = 1 << INT2;
|
||||||
|
EICRA |= 1 << ISC21 | 1 << ISC20;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
status_flags.button_press[i] = false;
|
||||||
|
}
|
||||||
|
status_flags.frame_timeout = false;
|
||||||
|
|
||||||
dio_set_direction(&status_light, LINE_OUT);
|
dio_set_direction(&status_light, LINE_OUT);
|
||||||
|
|
||||||
// Disable unneeded modules
|
// Disable unneeded modules
|
||||||
|
@ -77,12 +102,6 @@ int main(void) {
|
||||||
display_write_message(&display, "ready");
|
display_write_message(&display, "ready");
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
|
|
||||||
dio_t buttons[4] = {
|
|
||||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 },
|
|
||||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 6 },
|
|
||||||
{ .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 },
|
|
||||||
{ .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 6 },
|
|
||||||
};
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
dio_set_direction(&buttons[i], LINE_IN);
|
dio_set_direction(&buttons[i], LINE_IN);
|
||||||
}
|
}
|
||||||
|
@ -100,36 +119,28 @@ int main(void) {
|
||||||
lantern_step(&lantern, colors);
|
lantern_step(&lantern, colors);
|
||||||
sk9822_send(&lights, colors, LIGHT_COUNT);
|
sk9822_send(&lights, colors, LIGHT_COUNT);
|
||||||
|
|
||||||
// power_pulse_t timer = { .on = false, .timeout = PULSE_OFF_COUNT };
|
|
||||||
|
|
||||||
setup_fps_timer();
|
setup_fps_timer();
|
||||||
|
|
||||||
set_sleep_mode(SLEEP_MODE_IDLE);
|
set_sleep_mode(SLEEP_MODE_IDLE);
|
||||||
while(1) {
|
while(1) {
|
||||||
lantern_step(&lantern, colors);
|
if (status_flags.button_press[0]) {
|
||||||
sk9822_send(&lights, colors, LIGHT_COUNT);
|
status_flags.button_press[0] = false;
|
||||||
|
lantern_set_mode(&lantern, normal);
|
||||||
|
} else if (status_flags.button_press[1]) {
|
||||||
|
status_flags.button_press[1] = false;
|
||||||
|
lantern_set_mode(&lantern, spooky);
|
||||||
|
} else if (status_flags.button_press[2]) {
|
||||||
|
status_flags.button_press[2] = false;
|
||||||
|
lantern_set_mode(&lantern, eerie);
|
||||||
|
} else if (status_flags.frame_timeout) {
|
||||||
|
status_flags.frame_timeout = false;
|
||||||
|
lantern_step(&lantern, colors);
|
||||||
|
sk9822_send(&lights, colors, LIGHT_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
sleep_mode();
|
sleep_mode();
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
/*
|
|
||||||
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);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue