move data between memory addresses

Hi!

I'd like to write a program which controls an LED matrix. I've written the program to read my matrix, and turn the LED on where the value is one. Now I'd like to move one LED through the matrix, with changing its address. So if I attached a pushbutton later, i could move a LED through my matrix. But this code doesn't want to move my LED +3 forward on x and y matrix.

So I'd like to move my "1" from x0 y0 to x3 y3

The code works properly without SetLedPosition() function, I know the code is wrong somewhere there, please help me find out where.

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
// 2-dimensional array of row pin numbers:
const int row[8] = {
  2,7,19,5,13,18,12,16 };

// 2-dimensional array of column pin numbers:
const int col[8] = {
  6,11,10,3,17,4,8,9  }; 
  
int matrix[8][8]= {
  
  {1,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0},
  }; 
  
void setup() 
{
  //Set each pin to OUTPUT.
  for (int thisPin = 0; thisPin < 8; thisPin++) 
  {
    pinMode(col[thisPin], OUTPUT); 
    pinMode(row[thisPin], OUTPUT);
    digitalWrite(col[thisPin], HIGH); //Set each column to positive. (COLUMN SCAN).
  }
}

void loop()
{  
  RefreshScreen();
  SetLedPosition();
}

void SetLedPosition()
{
  int x;
  int y;
  GetLedPosition(x,y);
  int movex = x;
  int movey = y;
  x+3;
  y+3;
}
  
void GetLedPosition (int& x, int& y)
{
  for (int checkx=0; checkx<8; checkx++)
  {
    for(int checky=0; checky<8; checky++)
    {
      if (matrix[checkx][checky] == 1)
      {
        checkx = x;
        checky = y;
      }
    }
  }
}
        

void RefreshScreen ()
{
  for (int xpixel=0; xpixel<8; xpixel++)
  {
    for ( int ypixel=0; ypixel<8; ypixel++)
    {
      if (matrix[xpixel][ypixel] == 1)
      {
        pixel(xpixel,ypixel);
      }
    }
  }
}

void pixel (int x, int y)
{
  digitalWrite(row[x], HIGH);
  digitalWrite(col[y], LOW);
  digitalWrite(row[x], LOW);
  digitalWrite(col[y], HIGH);
}

        
  
Last edited on
Neither GetLedPosition nor SetLedPosition have any effect at all.

Neither x nor y are modified in GetLedPosition and in SetLedPosition only local variables which cease existing when the function returns are modified.
I can't see why what you have should work.

Have you considered just building a layer that allows you to get/set individual pixels. Then use that layer to render your output.
Topic archived. No new replies allowed.