summaryrefslogtreecommitdiffstats
path: root/Matrix_5x6/Charlie/Charlie.pde
blob: fa7f4a053b00ea7f74174a00bfe07485d3ff00e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <Charlieplex.h>

/* TODO:
   * Laufschrift
   * Ameise
   * Game of Life
   */

#define NUMBER_OF_PINS 6
byte pins[] = {2,3,4,5,6,7};
Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS);

charliePin ledi[] = { {0, 1} , {1, 0} , {2, 0} , {3, 0} , {4, 0} , {5, 0},
                      {0, 2} , {1, 2} , {2, 1} , {3, 1} , {4, 1} , {5, 1},
                      {0, 3} , {1, 3} , {2, 3} , {3, 2} , {4, 2} , {5, 2},
                      {0, 4} , {1, 4} , {2, 4} , {3, 4} , {4, 3} , {5, 3},
                      {0, 5} , {1, 5} , {2, 5} , {3, 5} , {4, 5} , {5, 4},
                    };

int scr[6][5];

void clrscr() {
  int x, y;
  for (x=0; x<6; x++) 
    for (y=0; y<5; y++)
      scr[x][y] = 0;
}

void drawscr(int c) {
  int x, y;
  int s;
  while (c--) {
    s = 20;
    while(s--)
      for (x=0; x<6; x++)
         for (y=0; y<5; y++) {
           charlieplex.charlieWrite(ledi[x+y*6], scr[x][y]>s?HIGH:LOW);
           charlieplex.clear();
         }
  
  }
}

void fadescr_down() {
  int x, y;
  for (x=0; x<6; x++) 
    for (y=0; y<5; y++)
      if (scr[x][y])
        scr[x][y] -= 1;
}

void fadescr_up() {
  int x, y;
  for (x=0; x<6; x++) 
    for (y=0; y<5; y++)
      if (scr[x][y] < 30)
        scr[x][y] += 1;
}


int an  = 2;
int aus = 10;

void setup(){ /*nothing*/ }
 
/* zufällige LEDs werden langsam dunkler */

void zufall_fading_down() {
  clrscr();
  int x, y;
  for (x=0; x<6; x++)
    for (y=0; y<5; y++)
      scr[x][y] = random(30);

  int i=30;

  while (i--) {
  drawscr(2); 
  fadescr_down();
  }  

}

/* zufällige LEDs werden langsam heller */

void zufall_fading_up() {
  clrscr();
  int x, y;
  for (x=0; x<6; x++)
    for (y=0; y<5; y++)
      scr[x][y] = - random(30);

  int i=50;

  while (i--) {
  drawscr(2); 
  fadescr_up();
  }  
}

/* schnecke mit vier startpunkten (0 bis 3) von außen nach innnen
   mit fading */

void schnecke(int s) {
  clrscr();
  int x, y, d, w = 0;
  d = s;
  switch(s) {
     case 0:
       x = 0;
       y = 0;
       break;
     case 1:
       x = 5;
       y = 0;
       break;
     case 2:
       x = 5;
       y = 4;
       break;
     case 3:
       x = 0;
       y = 4;
       break;
  }
  
  int i;
  i = 0;
  while (1) {
    i++;
    if (scr[x][y]) break;
    
    scr[x][y] = w?20:i+5;
    drawscr(2);
    fadescr_down();
    
    switch (d) {
      case 0: if (x == 5 - w) {d = 1; if (s == 2) w++;} break;
      case 1: if (y == 4 - w) {d = 2; if (s == 3) w++;} break;
      case 2: if (x == w) {d = 3; if (s == 0) w++;} break;
      case 3: if (y == w) {d = 0; if (s == 1) w++;} break;
    }
    
    switch (d) {
      case 0: x++; break;
      case 1: y++; break;
      case 2: x--; break;
      case 3: y--; break;
    }
  }
  
  i = 20;
  while(i--) {
    fadescr_down();
    drawscr(2);
  }
}

void loop() {
//  zufall_fading_up();
//  zufall_fading_down();
  schnecke(random(4));
}