use helper functions

This commit is contained in:
Olaf Rempel 2012-03-11 13:08:06 +01:00
parent f92a03776d
commit d2e2bb1695

27
main.c
View File

@ -130,12 +130,19 @@ void color_div(uint8_t *color, uint8_t div, uint8_t *output)
{
uint8_t i;
for (i = 0; i < 3; i++) {
if (color[i] != 0) {
output[i] = color[i] / div;
if ((output[i] == 0) && (color[i] != 0)) {
if (output[i] == 0) {
output[i] = 0x01;
}
} else {
output[i] = 0x00;
}
}
}
static uint8_t chan_decay[16][3];
int main(void) __attribute__ ((noreturn));
int main(void)
@ -152,7 +159,6 @@ int main(void)
uint8_t x = 0;
uint8_t xdir = 1;
uint16_t ramp = 0;
uint8_t step = 0;
/* wait for complete update */
rgb_update(COLOR_MASK, 1);
@ -163,24 +169,17 @@ int main(void)
/* wait for complete update */
rgb_update(COLOR_MASK, 1);
// _delay_ms(1);
_delay_ms(50);
#if 1
step++;
if (step == 16) {
step = 0;
x = sequence_chase(x, &xdir, 0x1F1F);
}
ramp = color_ramp(ramp +8, chan_value[x]);
color_div(chan_value[x], 4, chan_decay[x]);
uint8_t color[3] = { 0, 0, 0 };
ramp = color_ramp(ramp +1, chan_value[x]);
uint8_t i, j;
uint8_t i;
for (i = 0; i < 16; i++) {
if (x != i) {
chan_value[i][0] = 0;
chan_value[i][1] = 0;
chan_value[i][2] = 0;
color_sub(chan_value[i], chan_decay[i], chan_value[i]);
}
}
#endif