summaryrefslogtreecommitdiffstats
path: root/Matrix_3x3/Matrix_3x3.pde
blob: eea52e50d45a4805e391dc5da24268b81718c153 (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
/*
  Blink
 
 */
#define ROW 3
#define COL 0
#define ROWCNT 3
#define COLCNT 3

#define DELAY 3

int frame[3][3] = {
  {0, 0, 0},
  {0, 0, 0},
  {0, 0, 0},
};

int framenr = 0;
int rownr = 0;
void setup() {                
  // initialize the digital pin as an output.
  int i;
  for (i = 0;i < ROWCNT; i++)
    pinMode(ROW + i, OUTPUT); 
  for (i = 0;i < COLCNT; i++)
    pinMode(COL + i, OUTPUT);   
}

void nextFrame() {
  frame[0][0] = (framenr % 100) < 50;  
  frame[0][1] = (framenr % 100) < 50;  
  frame[0][2] = (framenr % 100) < 50;  
  frame[1][0] = (framenr % 100) < 50;  
  frame[1][1] = (framenr % 100) >= 50;  
  frame[1][2] = (framenr % 100) < 50;  
  frame[2][0] = (framenr % 100) < 50;  
  frame[2][1] = (framenr % 100) < 50;  
  frame[2][2] = (framenr % 100) < 50;  
}

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);
}