Problems with Arduino specific C++

Thread Starter

TheButtonThief

Joined Feb 26, 2011
237
Hi.

Currently writing the code for a 7-seg LED clock using 4 digits, an Arduino Uno and a HEF4511. I'm also currently pulling my hair out as I know the following code should work but it doesn't, the code multiplexes the LED display. I get an error "D was not declared in the scope" and "dig was not declared in the scope" with regards to digOn().

There's more code than what I've shown below but I don't think any of it is relative. If anyone would like to see the entire sketch, I'll gladly post it.

Thanks for taking a look

Jay


Code:
int D3 = 11; // Pin 11 to D3 of IC4511
int D2 = 10; // Pin 10 to D2 of IC4511
int D1 = 9;  // Pin 9 to D1 of IC4511
int D0 = 8;  // Pin 8 to D0 of IC4511

int dig0 = 4; // Pin 4 to digit 0 transistor (right right)
int dig1 = 5; // Pin 5 to digit 1 transistor (midle right)
int dig2 = 6; // Pin 6 to digit 2 transistor (midle left)
int dig3 = 7; // Pin 7 to digit 3 transistor (left left)

int number = 0; // Decimal number for output digit
int digOn; // Which digit to hold high

int binMatrix[][4] = { // Binary output to IC4511
{0,0,0,0},
{0,0,0,1},
{0,0,1,0},
{0,0,1,1},
{0,1,0,0},
{0,1,0,1},
{0,1,1,0},
{0,1,1,1},
{1,0,0,0},
{1,0,0,1}
};

int digMatrix[][4] = { // digit to be held high for muxing
{0,0,0,1}, // digit 0
{0,0,1,0}, // digit 1
{0,1,0,0}, // digit 2
{1,0,0,0}, // digit 3
};

void digitOn() { // write binary to multiplexer and mux digit

for (int I=0; i<=3; i++) {
  digitalWrite (D[i], binMatrix[number][i]);  // Output binary number via D0, D1, D2, D3 using binMatrix
  digitalWrite (dig[i], digMatrix[digOn][i]);  // Switch current digit high and the rest low using digMatrix
}//end for
}

void setup() {

pinMode (D0, OUTPUT);
pinMode (D1, OUTPUT);
pinMode (D2, OUTPUT);
pinMode (D3, OUTPUT);
pinMode (dig0, OUTPUT);
pinMode (dig1, OUTPUT);
pinMode (dig2, OUTPUT);
pinMode (dig3, OUTPUT);
}

voild loop() {

//lots of stuff here that works

}
 

Thread Starter

TheButtonThief

Joined Feb 26, 2011
237
so...
int D3 = 11; // Pin 11 to D3 of IC4511
int D2 = 10; // Pin 10 to D2 of IC4511
int D1 = 9; // Pin 9 to D1 of IC4511
int D0 = 8; // Pin 8 to D0 of IC4511
int D<I>;


...?
 

Thread Starter

TheButtonThief

Joined Feb 26, 2011
237
I think I know where I've gone wrong, it needs to look something like:

int D[] = {8, 9, 10, 11};
int dig[] = {4, 5, 6, 7};

Then...

void setup() {
for (int i=0; i<=3; i++) {
pinMode (D, OUTPUT);
pinMode (dig, OUTPUT);
}

Then...

void digitOn() { // write binary to multiplexer and mux digit

for (int i=0; i<=3; i++) {
digitalWrite (D, binMatrix[number]); // Output binary number via D0, D1, D2, D3 using binMatrix
digitalWrite (dig, digMatrix[digOn]); // Switch current digit high and the rest low using digMatrix
}//end for

}

I'll test it when I get home =)

Cheers
 

djsfantasi

Joined Apr 11, 2010
9,163
Your references to D and dig in your for loop need to be investigated. PinMode is expecting an int as the first parameter; you are passing a pointer (to the arrays). You have to qualify the parameters in pinMode to refer to only one element. You have a similar problem in digitOn and the digitalWrite call.

Your initialization looks good...
 

Thread Starter

TheButtonThief

Joined Feb 26, 2011
237
Ahh! I meant to do this...

Code:
int D[] = {8, 9, 10, 11};
int dig[] = {4, 5, 6, 7};
Then...


Code:
void setup() {

for (int i=0; i<=3; i++) {
  pinMode (D[i]OUTPUT);
  pinMode (dig[i], OUTPUT);
}

Then...


Code:
void digitOn() { // write binary to multiplexer and mux digit
  for (int i=0; i<=3; i++) {
    digitalWrite (D[i], binMatrix[number]); // Output binary umber via D0, D1, D2, D3 using binMatrix
    digitalWrite (dig[i], digMatrix[digOn]); // Switch current digit high and the rest low using digMatrix
  }//end for
}


I've seen other programs written in a similar way, for example I've seen the following many times before...

Code:
void setup() {
  for (int i=0; i<=5; i++) {
    pinMode (LEDpin[i], OUTPUT);  // set LED pins for Output
  }
}

However, the int's had been declared like this...

Code:
int LEDpin1 = 13;
int LEDpin2 = 12;
int LEDpin3 = 11;
int LEDpin4 = 10;
int LEDpin5 = 9;

and not like...

Code:
int LEDpin[6] = {13, 12, 11, 10, 9};

I'll see if I can get it to work by using an array to declare the int's


The whole project works if I use:

Code:
void digitOn() {  // write binary to BCD multiplexer and mux digit
  digitalWrite (D0, binMatrix[number][0]);
  digitalWrite (D1, binMatrix[number][1]);
  digitalWrite (D2, binMatrix[number][2]);
  digitalWrite (D3, binMatrix[number][3]);

  digitalWrite (dig0, digMatrix[digOn][0]);
  digitalWrite (dig1, digMatrix[digOn][1]);
  digitalWrite (dig2, digMatrix[digOn][2]);
  digitalWrite (dig3, digMatrix[digOn][3]);
}
 
Last edited:
Top