Add simple smooth animation

This commit is contained in:
fruchti 2020-07-16 23:11:09 +02:00
parent 187c915799
commit 5a45524af3
3 changed files with 26 additions and 3 deletions

View file

@ -1 +1 @@
361 373

View file

@ -286,6 +286,14 @@ LED_Colour_t Animation_GetColour(unsigned int step, unsigned int brightness)
void Animation_DrawGradient(unsigned int step_bottom, unsigned int step_top, void Animation_DrawGradient(unsigned int step_bottom, unsigned int step_top,
unsigned int brightness) unsigned int brightness)
{ {
if(step_bottom >= ANIMATION_STEPS)
{
step_bottom = 2 * ANIMATION_STEPS - step_bottom;
}
if(step_top >= ANIMATION_STEPS)
{
step_top = 2 * ANIMATION_STEPS - step_top;
}
for(int i = 0; i < LED_COUNT; i++) for(int i = 0; i < LED_COUNT; i++)
{ {
unsigned int step = ((LED_COUNT - 1 - i) * step_bottom + i * step_top) unsigned int step = ((LED_COUNT - 1 - i) * step_bottom + i * step_top)
@ -301,7 +309,17 @@ void Animation_Poll(void)
{ {
return; return;
} }
LED_FrameFlag = false;
Animation_DrawGradient(60000, 50000, LightSensor_RelativeBrightness); static unsigned int bottom = 0;
static unsigned int top = 0;
bottom += ANIMATION_STEPS / ANIMATION_DURATION_BOTTOM;
top += ANIMATION_STEPS / ANIMATION_DURATION_TOP;
bottom %= 2 * ANIMATION_STEPS;
top %= 2 * ANIMATION_STEPS;
Animation_DrawGradient(bottom, top, LightSensor_RelativeBrightness);
LED_Commit(); LED_Commit();
LED_FrameFlag = false;
} }

View file

@ -4,6 +4,11 @@
#define ANIMATION_STEPS 65535 #define ANIMATION_STEPS 65535
#define ANIMATION_DURATION_BOTTOM \
1000
#define ANIMATION_DURATION_TOP 5000
extern const unsigned int Animation_LEDOrder[LED_COUNT]; extern const unsigned int Animation_LEDOrder[LED_COUNT];
void Animation_Poll(void); void Animation_Poll(void);