Ich habe hier einen matrix effekt (Fallende Buchstaben) auf meiner
Wordclock.
Das funktioniert alles einwandfrei, sollange ich die auskommentierte for
Schleife verwende.
Sobald ich aber die while(1) Schleife nehme, verhält sich das "Programm"
etwas komisch, und neu eingefügte "Pixel" werden nicht nach unten
kopiert.
Woran könte das liegen?
1 | void matrix_effect(uint8_t direction, uint16_t duration)
|
2 | {
|
3 |
|
4 | uint8_t x,y,uart_zeichen;
|
5 | uint8_t feld[10][10];
|
6 | init_strip();
|
7 | if(direction == 1)
|
8 | {
|
9 | direction = 2;
|
10 | }
|
11 | //Feld nullen
|
12 | for(uint8_t i = 0; i<10; i++)
|
13 | {
|
14 | for(uint8_t j = 0; j<10; j++)
|
15 | {
|
16 | feld[i][j] = 0;
|
17 | }
|
18 | }
|
19 |
|
20 | ///Bit von oben einfüllen
|
21 |
|
22 | while(1)//for(uint16_t i = 0; i<duration; i++)
|
23 | {
|
24 |
|
25 | //Zu zufälligen Zeiten neue Pixel einfügen
|
26 | if(rand() % 4 > 2)
|
27 |
|
28 | {
|
29 | do
|
30 | {
|
31 | x = rand()%10;
|
32 | y = 9 - rand()%2;
|
33 | }
|
34 | while((feld[x][y] == 1)||(feld[x][y-1] == 1)||(feld[x][y-2] == 1));
|
35 | //Hier wird so lange eine Zufallszahl gesucht,
|
36 | //bis sie etwas weiter von einem schon vorhandenem Pixel liegt
|
37 |
|
38 |
|
39 | feld[x][y] = 1;
|
40 |
|
41 | }
|
42 | //Array nach unten kopieren
|
43 |
|
44 |
|
45 | for(uint8_t yc = 0; yc <9; yc++)
|
46 | {
|
47 | for(uint8_t xc = 0; xc <10; xc++)
|
48 | {
|
49 | feld[xc][yc] = feld[xc][yc+1];
|
50 | }
|
51 | }
|
52 | for(uint8_t xc = 0; xc <10; xc++)
|
53 | {
|
54 | feld[xc][9] = 0;
|
55 | }
|
56 |
|
57 |
|
58 |
|
59 | ///Feld Ausgeben
|
60 | for(uint8_t x = 0; x<10; x++)
|
61 | {
|
62 | for(uint8_t y = 0; y<10; y++)
|
63 | {
|
64 | if(feld[x][y]==1)
|
65 | put_pixel_on_strip(x,y,direction,0,1,0);
|
66 | }
|
67 | }
|
68 |
|
69 | if((UCSRA & (1<<RXC)))
|
70 | {
|
71 | uart_zeichen = UDR;
|
72 | if(uart_zeichen == 'e')
|
73 | {
|
74 | return;
|
75 | }
|
76 | }
|
77 | _delay_ms(900);
|
78 |
|
79 | }
|
80 | }
|