Pages: [1]   Go Down
Author Topic: 5x7 dot matrix  (Read 445 times)
0 Members and 1 Guest are viewing this topic.
Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all! I was trying to get a 5x7 dot matrix to work. I started with this:
Code:
int columns[]={13, 12, 11, 10, 9};
int rows[]={8, 7, 6, 5, 4, 3, 2};
void setup(){
  for(int i=0; i<=4; i++){
    pinMode(columns[i], OUTPUT);
  }
  for(int i=0; i<=6; i++){
    pinMode(rows[i], OUTPUT);
  }
}
void loop(){
  dot(2, 1);
}
void dot(int col, int row){
  for(int i=0; i<4; i++){
    digitalWrite(rows[i], LOW);
  }
  for(int i=0; i<6; i++){
    digitalWrite(columns[i], HIGH);
  }
  digitalWrite(rows[row], LOW);
  digitalWrite(columns[col], HIGH);
}
and what I get is a whole row lighting up. Why is this?
Logged

What is man's best friend? The breadboard!

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4014
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void dot(int col, int row)
{
  for(int i=0; i<4; i++)
  {
    digitalWrite(rows[i], LOW);
  }
  for(int i=0; i<6; i++)
  {
    digitalWrite(columns[i], HIGH);
  }
  digitalWrite(rows[row], LOW);
  digitalWrite(columns[col], HIGH);
}
It looks to me as though your rows and columns are mixed up in this function.  Also
Code:
  for(int i=0; i<6; i++)
loops 6 times and
Code:
  for(int i=0; i<4; i++)
loops 4 times but you say that your matrix is 5x7

How are the LEDs wired ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12520
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Delete all the hardcoded literal values for the number of rows and columns, and replace them with defined constants. For example:

Code:
const byte COLUMN_COUNT = 5;
const byte ROW_COUNT = 7;

When looping through rows and columns always use these values, like this:

Code:
for(int r = 0; r < ROW_COUNT; r++)
{
  digitalWrite(rows[r], LOW);
}
for(int c = 0; c < COLUMN_COUNT; c++)
{
  digitalWrite(columns[c], HIGH);
}
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot. I modified the code, here it is.
Code:
int columns[]={13, 12, 11, 10, 9};
int rows[]={8, 7, 6, 5, 4, 3, 2};
const byte COLUMN_COUNT=5;
const byte ROW_COUNT=7;
void setup(){
  for(int i=0; i<=4; i++){
    pinMode(columns[i], OUTPUT);
  }
  for(int i=0; i<=6; i++){
    pinMode(rows[i], OUTPUT);
  }
}
void loop(){
  dot(2, 1);
}
void dot(int col, int row){
  for(int i=0; i<=4; i++){
    digitalWrite(rows[i], HIGH);
  }
  for(int i=0; i<=6; i++){
    digitalWrite(columns[i], LOW);
  }
  digitalWrite(rows[row], LOW);
  digitalWrite(columns[col], HIGH);
}
My dot matrix is a generic 12 pin 5x7, I don't have a schematic. After modifing the code, the first, second, sixth and seventh rows of the first column light up.
Logged

What is man's best friend? The breadboard!

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12520
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot. I modified the code, here it is.

You have added the constant definitions but you have completely ignored all the other suggestions I made.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops... Sorry.
Logged

What is man's best friend? The breadboard!

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4690
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why use ints to count from 0 to less than 10?
Was that a conscious choice or just following a grooved-in habit to save actual thinking?
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: [1]   Go Up
Jump to: