step by step sequence animation

different intro animation
This commit is contained in:
daniel steuer 2014-03-17 01:02:51 +01:00
parent 0917b029e3
commit 1083def408

View File

@ -26,6 +26,7 @@
#define EXTEND_SEQUENCE 8
#define WIN 9
int8_t show_anim_sequence( uint32_t now, uint32_t animation_start );
int8_t show_intro( uint32_t now, uint32_t animation_start );
int8_t show_introduce_colors( uint32_t now, uint32_t animation_start );
void show_anim_wait_seed( uint32_t now, uint32_t animation_start );
@ -42,7 +43,6 @@ static uint8_t colorScheme[2];
void rgbyteclock(void) {
uint32_t now, t1;
uint16_t r,g,b; // colors
int8_t end;
uint8_t button = BUTTON_NONE;
@ -109,20 +109,9 @@ void rgbyteclock(void) {
break;
case SHOW_SEQUENCE:
// TODO: animation that shows sequence color after color
for( int i=0; i<sequence_index; i++ ) {
get_color( &r, &g, &b, sequence[i] );
led_set( i, r, g, b );
}
// display last color for 2 seconds
if( now - t1 > 2000 || (get_button())) {
// hide sequence
for( int i=0; i<12; i++ ) {
get_color( &r, &g, &b, COLOR_BLACK );
led_set( i, r, g, b);
}
end = show_anim_sequence( now, t1 );
if( end == 1 ) {
gameState = GET_USER_SEQUENCE;
t1 = now;
}
@ -247,6 +236,41 @@ int8_t get_sequence( uint32_t now, uint32_t animation_start ) {
##############
*/
int8_t show_anim_sequence( uint32_t now, uint32_t animation_start ) {
uint32_t t_diff = now - animation_start;
uint16_t r,g,b;
uint8_t tmp_index;
const uint16_t holdTime=1000 /*ms*/, stepSpeed=500 /*ms*/;
tmp_index = (t_diff/stepSpeed) +1;
if( tmp_index > sequence_index ) {
tmp_index = sequence_index;
}
for( int i=0; i<tmp_index; i++ ) {
get_color( &r, &g, &b, sequence[i] );
led_set( i, r, g, b );
}
// display last color for 2 seconds
if( t_diff > (sequence_index * stepSpeed)+holdTime ) {
// hide sequence
for( int i=0; i<12; i++ ) {
get_color( &r, &g, &b, COLOR_BLACK );
led_set( i, r, g, b);
}
return 1;
}
return 0;
}
int8_t show_introduce_colors( uint32_t now, uint32_t animation_start ) {
uint32_t t_diff = now - animation_start;
uint16_t r,g,b;
@ -307,19 +331,54 @@ int8_t show_intro( uint32_t now, uint32_t animation_start ) {
uint32_t t_diff = now - animation_start;
uint16_t r,g,b;
uint8_t index;
static uint8_t tmp_sequence[12], tmp;
static uint8_t step = 0;
index = (t_diff%1200)/100;
if( !(t_diff % 100) ) {
// every 100ms
get_color( &r, &g, &b, (random()%6)+1 );
led_set( index, r, g, b );
if( step == 0) {
for( int i=0; i<12; i++) {
tmp_sequence[i] = (random()%6)+1;
}
step = 1;
}
// next LED in line is dark to mark the update spot better
index++;
led_set( index%12, 0,0,0 );
index = (t_diff%1200)/100;
if( now - animation_start > 2400 ) {
// print a chain of random colors
if( !(t_diff % 100) && (step == 1) ) {
PORTC ^=(1<<PC5);
// every 100ms
get_color( &r, &g, &b, tmp_sequence[index] );
led_set( index, r, g, b );
// goto next animation sequence
if( t_diff > 1200 ) {
step = 2;
}
}
// rotate chain 180 degrees
if( !(t_diff % 100) && (step == 2) ) {
// barrelshift every 100ms
tmp = tmp_sequence[11];
for( int i=10; i>=0; i-- ) {
tmp_sequence[i+1] = tmp_sequence[i];
}
tmp_sequence[0] = tmp;
// update all at once
for(int i=0; i<12; i++ ) {
get_color( &r, &g, &b, tmp_sequence[i] );
led_set( i, r, g, b );
}
}
//led_set( index, r, g, b );
if( (now - animation_start) > 2400 ) {
step = 0;
return 1;
}
return 0;