// Matrixausgabe als Case void dcf77_signal_anim (char id) { display_clear_black(); switch (id) { case 0: dcf77_string_doanim ("Text0, Bsp: Zeit", 250, display_color_from_rgb (160, 160, 255) ); break; case 1: dcf77_string_doanim ("Text1, Bsp: Zeit und Datum", 250, display_color_from_rgb (127, 0, 255) ); break; case 2: dcf77_string_doanim ("Text2, Bsp: Datum", 250, display_color_from_rgb (255, 255, 0) ); break; case 3: dcf77_string_doanim ("Diese Laufschrift ist in Ihrem Land nicht verf\206gbar. Das tut uns (nicht) leid!", 250, display_color_from_rgb (255, 255, 255) ); dcf77_string_doanim ("Stoppt Zensursula, SOPA, PIPA, ACTA, ...!", 500, display_color_from_rgb (255, 0, 0) ); dcf77_string_doanim ("F\206r m\206ndigen Umgang mit Internet und Netzneutralit\204t!", 500, display_color_from_rgb (0, 255, 0) ); break; case 42: dcf77_string_doanim ("THE ANSWER TO LIFE, THE UNIVERSE AND EVERYTHING? 42!", 400, display_color_from_rgb (255, 255, 255) ); break; default: dcf77_string_doanim ("Text_Default, Zeit", 500, display_color_from_rgb (0, 255, 0) ); } }
void heart() { display_buffer_write_set(0); display_clear_black(); display_buffer_active_set(0); display_buffer_write_set(1); for(coord_t x = 0; x < DISPLAY_WIDTH; x++) { for(coord_t y = 0; y < DISPLAY_HEIGHT; y++) { display_pixel_set(x, y, display_color_from_rgb( 128 + 127 * y / (DISPLAY_HEIGHT - 1), 255 - 255 * (DISPLAY_HEIGHT - y - 1) / (DISPLAY_HEIGHT - 1), 128 - 128 * (DISPLAY_WIDTH - x - 1) / (DISPLAY_WIDTH - 1) ) ); } } time_sync(); for (uint16_t counter = 256; counter; --counter) { display_buffer_write_set(0); display_buffer_copy(1, 0); coord_t p = counter % DISPLAY_WIDTH; display_sprite_put_P(p, 0, 9, 8, display_color_from_rgb( 255, 0, 128 ), heart_data); if( DISPLAY_WIDTH - p < 9 ) { display_sprite_put_P(p - DISPLAY_WIDTH, 0, 9, 8, display_color_from_rgb( 255, 0, 128 ), heart_data); } if(counter & 1) { for(coord_t y = 0; y < DISPLAY_HEIGHT; y++) { color_t tmp = display[1][0][y]; for(coord_t x = 0; x < DISPLAY_WIDTH - 1; x++) { display[1][x][y] = display[1][x + 1][y]; } display[1][DISPLAY_WIDTH - 1][y] = tmp; } } delay_ms(50); } }
void matrix_code () { short pause = 100; byte toppoint[9] = {1, 2, 3, 3, 2, 4, 5, 1, 0}; byte frickl[7] = {9, 10, 4, 11, 6, 8, 0}; byte kiel[5] = {6, 4, 7, 8, 0}; byte *woerter[3] = {toppoint, frickl, kiel}; short lauf = 0; // randomSeed (micros() ); byte rgb[10][3] = {{0, 255, 0}, {0, 159, 0}, {0, 127, 0}, {0, 95, 0}, {0, 63, 0}, {0, 63, 0}, {0, 63, 0}, {0, 63, 0}, {0, 63, 0}, {0, 63, 0}}; struct zeichenkette { signed short x; byte *font; byte fontzahl; signed short zyklus; }; short anzahl = DISPLAY_WIDTH / 8; struct zeichenkette zeichen[anzahl]; short tmp = 0; for (short i = 0; i < anzahl; i++) { //init zeichen zeichen[i].zyklus = random_range (0, 6) - 5; zeichen[i].x = i * 8 + random_range (0, 3); tmp = random_range (0, sizeof (woerter) / sizeof (byte*) ); zeichen[i].font = woerter[tmp]; tmp = 0; while (zeichen[i].font[tmp] != 0) { tmp++; } zeichen[i].fontzahl = tmp; } while (lauf < 100) { // anzahl schritte display_buffer_swap (1); for (short i = 0; i < anzahl; i++) { if ( (zeichen[i].zyklus >= 0) && (zeichen[i].zyklus < zeichen[i].fontzahl * 5 + DISPLAY_HEIGHT) ) { for (short j = 0; j < zeichen[i].fontzahl; j++) { //einzelne buchstaben durchlaufen uint8_t charid = zeichen[i].font[zeichen[i].fontzahl - j - 1]; uint16_t charbmp = pgm_read_word ( &fontmap[charid] ); for (byte ix = 0; ix < 4; ix++) { for (byte iy = 0; iy < 4; iy++) { if ( (charbmp & 1) != 0 ) { display_pixel_set (ix + zeichen[i].x, iy + j * 5 + zeichen[i].zyklus - zeichen[i].fontzahl * 5, display_color_from_rgb ( rgb[zeichen[i].fontzahl - j - 1][0], rgb[zeichen[i].fontzahl - j - 1][1], rgb[zeichen[i].fontzahl - j - 1][2] ) ); } charbmp >>= 1; } } } zeichen[i].zyklus++; } else if (zeichen[i].zyklus < 0) { //warte, bis die zeit reif ist zeichen[i].zyklus++; } else { //neu initialisieren zeichen[i].zyklus = random_range (0, 10) - 9; zeichen[i].x = i * 8 + random_range (0, 3); tmp = random_range (0, sizeof (woerter) / sizeof (byte*) ); zeichen[i].font = woerter[tmp]; tmp = 0; while (zeichen[i].font[tmp] != 0) { tmp++; } zeichen[i].fontzahl = tmp; } } delay_ms (pause); lauf++; }
// Funktion um serial.println durch Matrixausgabe zu ersetzen. Quelltext ersetzen von "string." durch "matrix_" void matrix_println (char *s) { dcf77_string_doanim (s, 250, display_color_from_rgb (127, 0, 255) ); }
void PlayPong(void) { display_buffer_write_set(0); display_clear_black(); display_buffer_active_set(0); display_buffer_write_set(1); display_clear_black(); for(coord_t y = 1; y < DISPLAY_HEIGHT; y+=2) { display_pixel_set(DISPLAY_WIDTH / 2, y, display_color_from_rgb(128, 128, 128)); display_pixel_set(DISPLAY_WIDTH - DISPLAY_WIDTH / 2 - 1, y, display_color_from_rgb(128, 128, 128)); } display_pixel_set(DISPLAY_WIDTH / 2, 0, 0377); display_pixel_set(DISPLAY_WIDTH - DISPLAY_WIDTH / 2 - 1, 0, 0377); int pts_player1 = 0, pts_player2 = 0; int pts_max = (DISPLAY_WIDTH - 1) / 2; int ball_dx = random_range(0, 2) ? 1 : -1; while( (pts_player1 < pts_max) && (pts_player2 < pts_max) ) { display_buffer_copy(1, 2); display_buffer_write_set(2); for(coord_t x = 0; x < pts_player1; x++) { display_pixel_set(DISPLAY_WIDTH - DISPLAY_WIDTH / 2 - x - 2, 0, ~x&1 ? 0007 : 0002); } for(coord_t x = 0; x < pts_player2; x++) { display_pixel_set(DISPLAY_WIDTH / 2 + x + 1, 0, ~x&1 ? 0070 : 0020); } int ball_x = DISPLAY_WIDTH / 2; if (ball_dx < 1) ball_x = DISPLAY_WIDTH - DISPLAY_WIDTH / 2 - 1; int ball_y = DISPLAY_HEIGHT / 2; int ball_dy = 1; int pad_player1 = DISPLAY_HEIGHT / 2; int pad_player2 = DISPLAY_HEIGHT / 2; int step = 0; while( (ball_x >= 0) && (ball_x < DISPLAY_WIDTH) ) { display_buffer_copy(2, 0); display_buffer_write_set(0); //Unser Ball display_pixel_set(ball_x, ball_y, 0377); //Die Schläger for(int i = -1; i <= 1; i++) { display_pixel_set(0, pad_player1 + i, 007); display_pixel_set(DISPLAY_WIDTH - 1, pad_player2 + i, 070); } //Reflektion am Schläger if(0 == ball_x) { if(abs (pad_player1 - ball_y) < 2) { ball_dx = 1; ball_dy = random_range(-2, 2); if(0 <= ball_dy) ball_dy++; } } else if(DISPLAY_WIDTH - 1 == ball_x) { if(abs (pad_player2 - ball_y) < 2) { ball_dx = -1; ball_dy = random_range(-2, 2); if(0 <= ball_dy) ball_dy++; } } //Ballbewegung simulieren ball_x += ball_dx; ball_y += ball_dy; step++; if(ball_y < 1) { ball_y = (1 - ball_y)/*delta am Spiegel*/ + 1/*Offset des Spiegels*/; ball_dy = abs(ball_dy); } else if(ball_y > DISPLAY_HEIGHT - 1) { ball_y = (DISPLAY_HEIGHT - 1)/*Offset des Spiegels*/ - (ball_y - DISPLAY_HEIGHT + 1)/*delta am Spiegel*/; ball_dy = -abs(ball_dy); } if( random_range(0, 3) ) { if( (ball_y < pad_player1) && (pad_player1 > 2) ) { pad_player1--; } if( (ball_y < pad_player2) && (pad_player2 > 2) ) { pad_player2--; } if( (ball_y > pad_player1) && (pad_player1 < DISPLAY_HEIGHT - 2) ) { pad_player1++; } if( (ball_y > pad_player2) && (pad_player2 < DISPLAY_HEIGHT - 2) ) { pad_player2++; } } delay_ms(25); } if(ball_x < 0) { pts_player2+=2; } else { pts_player1+=2; } delay_ms(500); } }