summaryrefslogtreecommitdiffstats
path: root/Matrix_7x13/Matrix_7x13.pde
blob: 377eda285add337b9002de9920e1dd2b1be9ee0a (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
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
#define ROW 3
#define COL 0
#define ROWCNT 7
#define COLCNT 13
#define CHARWIDTH 5
#define FRAMELEN 10

#define DELAY 3

int frame[COLCNT][ROWCNT] = {0};

/*const int frame_A[ROWCNT][CHARWIDTH] = {
  {0, 0, 1, 0, 0},
  {0, 0, 1, 0, 0},
  {0, 1, 0, 1, 0},
  {0, 1, 0, 1, 0},
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
};*/

/*const int frame_C[CHARWIDTH][ROWCNT] = {
  {0, 0, 1, 1, 1},
  {0, 1, 1, 0, 0},
  {1, 1, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 1, 0, 0, 0},
  {0, 1, 1, 0, 0},
  {0, 0, 1, 1, 1},
};

const int frame_H[ROWCNT][CHARWIDTH] = {
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
};

const int frame_L[ROWCNT][CHARWIDTH] = {
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 0, 0, 0, 0},
  {1, 1, 1, 1, 1},
};*/

const int frame_MINUS[CHARWIDTH][ROWCNT] = {
  {0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0},
  {0, 0, 0, 1, 0, 0, 0},
};

const int emptyCol[ROWCNT] = {0};

unsigned long int framenr = 0;
int rownr = 0;
void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  int i;
  for (i = 0;i < ROWCNT; i++)
    pinMode(ROW + i, OUTPUT); 
  for (i = 0;i < COLCNT; i++)
    pinMode(COL + i, OUTPUT);   
}

void setCol(int c, const int data[ROWCNT]) {
  int r;
  
  if (c > 0 && c <= COLCNT) {
    for (r = 0; r < ROWCNT; r++)
      frame[c][r] = data[r];
  }
}

void setChar(int c, const int data[CHARWIDTH][ROWCNT]) {
  int i;
  for (i = 0; i < CHARWIDTH; i++)
    setCol(c+i, data[i]);
}

void clearFrame() {
  int i = 0;
  for (i = 0; i < COLCNT; i++)
    setCol(i, emptyCol);
}

void nextFrame() {
  int c;
  int f2 = (framenr/FRAMELEN) % (COLCNT+CHARWIDTH);

  clearFrame();
  setChar(COLCNT-f2, frame_MINUS);
}

void loop() {
  int i;
  
  rownr = ( rownr + 1 ) % ROWCNT;
 
  if (rownr == 0) {
    framenr++;
    nextFrame();
  }
 
  for (i = 0; i < COLCNT; i++) {
    digitalWrite(COL + i, frame[rownr][i]);  
  }
  digitalWrite(ROW + rownr, HIGH);
  delay(DELAY);
  digitalWrite(ROW + rownr, LOW);
}