diff --git a/rgbyteclock.c b/rgbyteclock.c index 1a259ae..e8c5371 100644 --- a/rgbyteclock.c +++ b/rgbyteclock.c @@ -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 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 (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< 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;