summaryrefslogtreecommitdiffstats
path: root/Matrix_5x6/Matrix_5x6.pde
blob: 8f95209d4c678efd67d3292c716ad4b867b611ca (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
164
165
166
167
168
169
170
171
172
173
174
/*
5x6 LEDs Text scroller
Frank Bartels 2010
 */

#define leaner 1 // 0:std 1:normal 2:lean
//char myoutstring[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ  ";
//char myoutstring[]="0123456789  ";
//char myoutstring[]="789";
char myoutstring[]="TOPPOINT KIEL FRICKL 27C3 ";
int myoutstringpos=0;

#define NledPins 6
int ledPins[NledPins] = { 7,6,5,4,3,2 };

int i, j, k, x,y,xx,yy, lum=0,newscr=0,tmp;
int scrollx,scrolly;
#define SCRdx 5
#define SCRdy 6
#define OSf 4 // oversampling factor    <=5, sonst Speicher voll!

// int=2 ByteFRICKL FRICKL 
int scr[SCRdx][SCRdy]; // (real) screen
int vscr[SCRdx*OSf][SCRdy*OSf]; // virtual (high res) screen

#define CFONTwidth  0x5 // (font constant)
#define CFONTwidth2 0x7 // with std space between chars std=7
#define CFONTstart 0x20
#define CFONTend   0x5b
char cfont[]=
{ 0x00, 0x00, 0x00, 0x00, 0x00, // 0x20
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x21
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x22
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x23
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x24
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x25
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x26
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x27
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x28
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x29
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x2a
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x2b
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x2c
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x2d
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x2e
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x2f
  //0x1e, 0x31, 0x29, 0x25, 0x1e, // 0x30 0
  0x1e, 0x21, 0x2d, 0x21, 0x1e, // 0x30 0
  0x00, 0x22, 0x3f, 0x20, 0x00, // 0x31 1
  0x22, 0x31, 0x29, 0x29, 0x26, // 0x32 2
  0x12, 0x21, 0x25, 0x25, 0x1a, // 0x33 3
  0x18, 0x14, 0x12, 0x3f, 0x10, // 0x34 4
  0x22, 0x25, 0x25, 0x25, 0x18, // 0x35 5
  //0x1e, 0x29, 0x29, 0x29, 0x1a, // 0x36 6
  0x1e, 0x25, 0x25, 0x25, 0x18, // 0x36 6
  0x01, 0x01, 0x31, 0x0d, 0x03, // 0x37 7
  0x1a, 0x25, 0x25, 0x25, 0x1a, // 0x38 8
  0x06, 0x29, 0x29, 0x29, 0x1e, // 0x39 9
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x3a
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x3b
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x3c
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x3d
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x3e
  0x00, 0x00, 0x00, 0x00, 0x00, // 0x3f
  
  0x00, 0x00, 0x00, 0x00, 0x00, // SPACE (0x40 or 0x20)
  0x38, 0x16, 0x11, 0x16, 0x38, // A     (0x41)
  0x3f, 0x25, 0x25, 0x26, 0x18, // B     (0x42)
  0x1e, 0x21, 0x21, 0x21, 0x12, // C
  0x3f, 0x21, 0x21, 0x21, 0x1e, // D
  0x3f, 0x25, 0x25, 0x25, 0x21, // E
  0x3f, 0x05, 0x05, 0x05, 0x01, // F
  0x1e, 0x21, 0x21, 0x29, 0x1a, // G
  0x3f, 0x08, 0x08, 0x08, 0x3f, // H
  0x00, 0x21, 0x3f, 0x21, 0x00, // I
  0x00, 0x11, 0x21, 0x1f, 0x00, // J
  0x3f, 0x08, 0x14, 0x14, 0x22, // K
  0x3f, 0x20, 0x20, 0x20, 0x20, // L
  0x3f, 0x02, 0x0c, 0x02, 0x3f, // M
  0x3f, 0x02, 0x04, 0x08, 0x3f, // N
  0x1e, 0x21, 0x21, 0x21, 0x1e, // O
  0x3f, 0x09, 0x09, 0x09, 0x06, // P
  0x1e, 0x21, 0x29, 0x11, 0x2e, // Q
  0x3f, 0x09, 0x09, 0x19, 0x26, // R
  0x22, 0x25, 0x25, 0x25, 0x18, // S
  0x01, 0x01, 0x3f, 0x01, 0x01, // T
  0x1f, 0x20, 0x20, 0x20, 0x1f, // U
  0x03, 0x0c, 0x30, 0x0c, 0x03, // V
  0x3f, 0x10, 0x0c, 0x10, 0x3f, // W
  0x31, 0x0a, 0x04, 0x0a, 0x31, // X
  0x01, 0x02, 0x3c, 0x02, 0x01, // Y
  0x31, 0x29, 0x25, 0x23, 0x21, // Z
};

volatile int dummy;

void setup()
{ for (int i=0; i<NledPins; i++)
    pinMode(ledPins[i], INPUT);     
}

void vscr2scr()
{ int x,y,xx,yy,xxx,yyy,sum;
  for(x=0; x<SCRdx; x++) 
  { xxx=x*OSf;
    for(y=0; y<SCRdy; y++)
    { yyy=y*OSf;
      sum=0;
      for(xx=0; xx<OSf; xx++) for(yy=0; yy<OSf; yy++) sum+=vscr[xxx+xx][yyy+yy];
      scr[x][y]=sum/OSf/OSf;
    }
  }
}

#define ANIMm (20)
int lum2=0;
void loop()                     
{ newscr++;
  if (newscr%(ANIMm)==0)
  { //int p0=myoutstringpos/OSf;
 
    //int p0=myoutstringpos/(OSf-1); // Zeichen nur (OSf-1)/OSf breit ausgeben
    //int p0=myoutstringpos/(OSf-leaner); // Zeichen nur (OSf-1)/OSf breit ausgeben
    int p0=myoutstringpos*42/100; // Zeichen nur (OSf-1)/OSf breit ausgeben
 
    int p2=p0/CFONTwidth2;
    char c=myoutstring[p2];
    if (c==0) { myoutstringpos=0; p0=0; p2=p0/CFONTwidth2; c=myoutstring[p2]; }
    int p1=p0%CFONTwidth2;
    int bits=0;
    if (c==0x20) c=0x40; // 0x40 is SPACE !
    if (p1<CFONTwidth && c<CFONTend) bits=cfont[(c-CFONTstart)*CFONTwidth+p1];
    for (int b=1, p=0; b<0x40 && p<OSf*6; b*=2, p+=OSf) if (bits&b)
      for(y=0; y<OSf; y++) vscr[OSf*SCRdx-1][p+y]=256;
    myoutstringpos++;
    
    for(y=0; y<SCRdy*OSf; y++)
    { for(x=0; x<SCRdx*OSf-1; x++) vscr[x][y]=vscr[x+1][y];
      vscr[SCRdx*OSf-1][y]=0;  // clear
    }
    vscr2scr();
  }
  
  lum+=16; if (lum>254) lum=0;
  
  int xx=-1;
  int yy=-1;
  for (int y=0; y<NledPins; y++)
  { digitalWrite(ledPins[y], HIGH);
    pinMode(ledPins[y], OUTPUT);     
    for (int x=0; x<NledPins; x++)
      if (x==y)
      { xx=(xx+1)%NledPins;
        yy++;
      }
      else
      { xx=(xx+1)%NledPins;
        lum2= (lum2+23) & 0xFF;
        //if (xx==0 && yy==0)
        //if (xx==yy)
        //if (scr[yy][xx]>lum2) // (real) screen
        //if (scr[yy][xx]+48<lum2) // inverted
        if (scr[yy][xx]-48 > lum2*13/16) // good for font scroll
        { //digitalWrite(ledPins[x], LOW); // digitalWrite(ledPins[y], LOW); (ganz unten)
          pinMode(ledPins[x], OUTPUT);     
          //for (int ll=0; ll!=10; ll++) for (int l=0; l!=0x7fff; l++) dummy=l;
          for (int l=0; l!=0x80; l++) dummy=l;
          pinMode(ledPins[x], INPUT);
        }
      }
    pinMode(ledPins[y], INPUT);     
    digitalWrite(ledPins[y], LOW);
  }
}