Function Error.. New and Stumped.

Im trying to build my own boost gauge using a seven segment display, arduino uno, and a pressure sensor. the code I have so far is giving me an error can anyone help me out? I don't know what the problem is?

The problem is somehow with the calling of the function. However I don't know what changes to make?

ERROR
Boost_Final.cpp.o: In function loop': C:\Program Files (x86)\Arduino/Boost_Final.ino:179: undefined reference to writenum(int, int)'
collect2.exe: error: ld returned 1 exit status
Error compiling.

CODE
void setup() {
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
pinMode (12, OUTPUT);
pinMode (13, OUTPUT);
}

void loop() {

int digit;
int num;

void writenum(int digit, int num);
{
if (digit==1){

analogWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
analogWrite(11, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(12, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(13, LOW); // Chooses digit ? and lights up what are grounded
}
else if (digit==2){

analogWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
analogWrite(11, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(12, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(13, LOW); // Chooses digit ? and lights up what are grounded
}
else if (digit==3){

analogWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
analogWrite(11, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(12, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(13, LOW); // Chooses digit ? and lights up what are grounded
}
else if (digit==4){

analogWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
analogWrite(11, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(12, LOW); // Chooses digit ? and lights up what are grounded
analogWrite(13, LOW); // Chooses digit ? and lights up what are grounded
}

if (num==0){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, LOW); // Ground the segment c
analogWrite(5, LOW); // Ground the segment d
analogWrite(6, LOW); // Ground the segment e
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, HIGH); //
analogWrite(9, HIGH); //
}

else if (num==1){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, HIGH); //
analogWrite(5, HIGH); //
analogWrite(6, HIGH); //
analogWrite(7, HIGH); //
analogWrite(8, HIGH); //
analogWrite(9, HIGH); //
}
else if (num==2){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, HIGH); //
analogWrite(4, LOW); // Ground the segment c
analogWrite(5, LOW); // Ground the segment d
analogWrite(6, HIGH); //
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, LOW); // Ground the segment g
analogWrite(9, HIGH); //
}
else if (num==3){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, LOW); // Ground the segment c
analogWrite(5, HIGH); //
analogWrite(6, HIGH); //
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, LOW); // Ground the segment g
analogWrite(9, HIGH); //
}
else if (num==4){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, HIGH); //
analogWrite(5, HIGH); //
analogWrite(6, LOW); // Ground the segment e
analogWrite(7, HIGH); //
analogWrite(8, LOW); // Ground the segment g
analogWrite(9, HIGH); //
}
else if (num==5){
analogWrite(2, HIGH); //
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, LOW); // Ground the segment c
analogWrite(5, HIGH); //
analogWrite(6, LOW); // Ground the segment e
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, LOW); // Ground the segment g
analogWrite(9, HIGH); //
}
else if (num==6){
analogWrite(2, HIGH); //
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, LOW); // Ground the segment c
analogWrite(5, LOW); // Ground the segment d
analogWrite(6, LOW); // Ground the segment e
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, LOW); // Ground the segment g
analogWrite(9, LOW); // Ground the segment DP
}
else if (num==7){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, HIGH); //
analogWrite(5, HIGH); //
analogWrite(6, HIGH); //
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, HIGH); //
analogWrite(9, HIGH); //
}
else if (num==8){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, LOW); // Ground the segment c
analogWrite(5, LOW); // Ground the segment d
analogWrite(6, LOW); // Ground the segment e
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, LOW); // Ground the segment g
analogWrite(9, HIGH); //
}
else if (num==9){
analogWrite(2, LOW); // Ground the segment a
analogWrite(3, LOW); // Ground the segment b
analogWrite(4, LOW); // Ground the segment c
analogWrite(5, HIGH); //
analogWrite(6, LOW); // Ground the segment e
analogWrite(7, LOW); // Ground the segment f
analogWrite(8, LOW); // Ground the segment g
analogWrite(9, HIGH); //
}
else if (num==10){
analogWrite(2, HIGH); //
analogWrite(3, HIGH); //
analogWrite(4, HIGH); //
analogWrite(5, HIGH); //
analogWrite(6, HIGH); //
analogWrite(7, HIGH); //
analogWrite(8, HIGH); //
analogWrite(9, LOW); // Ground the segment DP
}
else if (num==11){
analogWrite(2, HIGH); //
analogWrite(3, HIGH); //
analogWrite(4, HIGH); //
analogWrite(5, HIGH); //
analogWrite(6, HIGH); //
analogWrite(7, HIGH); //
analogWrite(8, LOW); // Ground the segment for negative
analogWrite(9, HIGH); //
}
} //End Function List

int x = 3;
int y = 9;
writenum(x,y);

}

Replace this line:

void writenum(int digit, int num);

for:

void writenum(int digit, int num)

Can you see the difference?

That's not going to fix it.
You need to not embed a function inside another.

And code tags, yes, we really like the code tag habit.

This is true! The function writenum() is inside the loop().

Without the code brackets, the code looks so bad...

giova014:
This is true! The function writenum() is inside the loop().

Right, I was going to say then I get this error. While highlighting the last } in the code.

Boost_Final.ino: In function 'void loop()':
Boost_Final:188: error: expected ';' before '}' token
expected ';' before '}' token

Should I make my own loop to run my function?

Or am I incorrectly writing the function code?

void writenum(int digit, int num);
{

How do I address the digit and the num inside the coding of the function?

Take another look at reply 1.
Move void writenum(int digit, int num) either before or after void loop()--but not inside setup() or any other function.
See what happens and let us know.

regards,
Michael

This is your code, cleaned up:

int digit;
int num;

void setup() {
  for (byte n = 2; n <= 13; n++)
    pinMode (n, OUTPUT);
}

void loop() {
  int x = 3;
  int y = 9;
  writenum(x, y);
}

void writenum(int digit, int num) {
  switch (digit) {

    case 1:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;

    case 2:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;

    case 3:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;

    case 4:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;
  }

  switch (num) {
    case 0:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, HIGH); //
      digitalWrite(9, HIGH); //
      break;

    case 1:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, HIGH); //
      digitalWrite(8, HIGH); //
      digitalWrite(9, HIGH); //
      break;

    case 2:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, HIGH); //
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, HIGH); //
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

    case 3:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

    case 4:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, HIGH); //
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

    case 5:
      digitalWrite(2, HIGH); //
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, HIGH); //
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

    case 6:
      digitalWrite(2, HIGH); //
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, LOW); // Ground the segment DP
      break;

    case 7:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, HIGH); //
      digitalWrite(9, HIGH); //
      break;

    case 8:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

    case 9:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, HIGH); //
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

    case 10:
      digitalWrite(2, HIGH); //
      digitalWrite(3, HIGH); //
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, HIGH); //
      digitalWrite(8, HIGH); //
      digitalWrite(9, LOW); // Ground the segment DP
      break;

    case 11:
      digitalWrite(2, HIGH); //
      digitalWrite(3, HIGH); //
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, HIGH); //
      digitalWrite(8, LOW); // Ground the segment for negative
      digitalWrite(9, HIGH); //
      break;
  }
}

Use the switch() when comparing the same variable with multiple values.
Use digitalWrite() when writing HIGH and LOW values to a Digital Pin.

My next error is the following...

Boost_Final:185: error: expected constructor, destructor, or type conversion before '(' token
expected constructor, destructor, or type conversion before '(' token

Any ideas?

giova014:
This is your code, cleaned up:

int digit;

int num;

void setup() {
  for (byte n = 2; n <= 13; n++)
    pinMode (n, OUTPUT);
}

void loop() {
  int x = 3;
  int y = 9;
  writenum(x, y);
}

void writenum(int digit, int num) {
  switch (digit) {

case 1:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;

case 2:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;

case 3:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;

case 4:
      digitalWrite(10, HIGH); // Chooses digit ? and lights up what are grounded
      digitalWrite(11, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(12, LOW); // Chooses digit ? and lights up what are grounded
      digitalWrite(13, LOW); // Chooses digit ? and lights up what are grounded
      break;
  }

switch (num) {
    case 0:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, HIGH); //
      digitalWrite(9, HIGH); //
      break;

case 1:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, HIGH); //
      digitalWrite(8, HIGH); //
      digitalWrite(9, HIGH); //
      break;

case 2:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, HIGH); //
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, HIGH); //
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

case 3:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

case 4:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, HIGH); //
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

case 5:
      digitalWrite(2, HIGH); //
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, HIGH); //
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

case 6:
      digitalWrite(2, HIGH); //
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, LOW); // Ground the segment DP
      break;

case 7:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, HIGH); //
      digitalWrite(9, HIGH); //
      break;

case 8:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, LOW); // Ground the segment d
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

case 9:
      digitalWrite(2, LOW); // Ground the segment a
      digitalWrite(3, LOW); // Ground the segment b
      digitalWrite(4, LOW); // Ground the segment c
      digitalWrite(5, HIGH); //
      digitalWrite(6, LOW); // Ground the segment e
      digitalWrite(7, LOW); // Ground the segment f
      digitalWrite(8, LOW); // Ground the segment g
      digitalWrite(9, HIGH); //
      break;

case 10:
      digitalWrite(2, HIGH); //
      digitalWrite(3, HIGH); //
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, HIGH); //
      digitalWrite(8, HIGH); //
      digitalWrite(9, LOW); // Ground the segment DP
      break;

case 11:
      digitalWrite(2, HIGH); //
      digitalWrite(3, HIGH); //
      digitalWrite(4, HIGH); //
      digitalWrite(5, HIGH); //
      digitalWrite(6, HIGH); //
      digitalWrite(7, HIGH); //
      digitalWrite(8, LOW); // Ground the segment for negative
      digitalWrite(9, HIGH); //
      break;
  }
}




Use the switch() when comparing the same variable with multiple values.
Use digitalWrite() when writing HIGH and LOW values to a Digital Pin.

Thanks!!!!!!!!!!!!!!!!!!!!!!! I wasn't quite sure how to use the Switch function... I see now!! I really appreciate it!!