step by step sequence animation
different intro animation
This commit is contained in:
parent
0917b029e3
commit
1083def408
105
rgbyteclock.c
105
rgbyteclock.c
@ -26,6 +26,7 @@
|
|||||||
#define EXTEND_SEQUENCE 8
|
#define EXTEND_SEQUENCE 8
|
||||||
#define WIN 9
|
#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_intro( uint32_t now, uint32_t animation_start );
|
||||||
int8_t show_introduce_colors( 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 );
|
void show_anim_wait_seed( uint32_t now, uint32_t animation_start );
|
||||||
@ -42,7 +43,6 @@ static uint8_t colorScheme[2];
|
|||||||
|
|
||||||
void rgbyteclock(void) {
|
void rgbyteclock(void) {
|
||||||
uint32_t now, t1;
|
uint32_t now, t1;
|
||||||
uint16_t r,g,b; // colors
|
|
||||||
int8_t end;
|
int8_t end;
|
||||||
uint8_t button = BUTTON_NONE;
|
uint8_t button = BUTTON_NONE;
|
||||||
|
|
||||||
@ -109,20 +109,9 @@ void rgbyteclock(void) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SHOW_SEQUENCE:
|
case SHOW_SEQUENCE:
|
||||||
// TODO: animation that shows sequence color after color
|
end = show_anim_sequence( now, t1 );
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if( end == 1 ) {
|
||||||
gameState = GET_USER_SEQUENCE;
|
gameState = GET_USER_SEQUENCE;
|
||||||
t1 = now;
|
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 ) {
|
int8_t show_introduce_colors( uint32_t now, uint32_t animation_start ) {
|
||||||
uint32_t t_diff = now - animation_start;
|
uint32_t t_diff = now - animation_start;
|
||||||
uint16_t r,g,b;
|
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;
|
uint32_t t_diff = now - animation_start;
|
||||||
uint16_t r,g,b;
|
uint16_t r,g,b;
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
static uint8_t tmp_sequence[12], tmp;
|
||||||
|
static uint8_t step = 0;
|
||||||
|
|
||||||
index = (t_diff%1200)/100;
|
if( step == 0) {
|
||||||
if( !(t_diff % 100) ) {
|
for( int i=0; i<12; i++) {
|
||||||
// every 100ms
|
tmp_sequence[i] = (random()%6)+1;
|
||||||
get_color( &r, &g, &b, (random()%6)+1 );
|
}
|
||||||
led_set( index, r, g, b );
|
step = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// next LED in line is dark to mark the update spot better
|
index = (t_diff%1200)/100;
|
||||||
index++;
|
|
||||||
led_set( index%12, 0,0,0 );
|
|
||||||
|
|
||||||
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 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user