Need Help with was seems to be Syntax Errors

My program is meant to be able to display an output of a pontentiometer mapped from 0-99 into 2 7 "7 panel displays" made of 14 LEDs. I believe that the code I have it correct but I have been told by my proffessor that my syntax is wrong in many places... If you guys could please lend some help as to where I can correct my code, it would be greatly appreciated.

int y = 0;
int x = 0;
int number = 0;
int sensorvalue = 0;
int pin0 = 0;
int pin1 = 1;
int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int pin8 = 8;
int pin9 = 9;
int pin10 = 10;
int pin11 = 11;
int pin12 = 12;
int pin13 = 13;

void setup()
 {
   pinMode(pin0, OUTPUT);
pinMode(pin1, OUTPUT);   
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin8, OUTPUT);
pinMode(pin9, OUTPUT);
pinMode(pin10, OUTPUT);
pinMode(pin11, OUTPUT);
pinMode(pin12, OUTPUT);
pinMode(pin13, OUTPUT);
 }

 

void loop() {
sensorvalue=analogRead(A2);
number=map(sensorvalue,0,1023,0,99);
y=number%10;
x=(number/10)-y;
switch (x){
case 1: one(1);
case 2: two(1);
case 3: three(1);
case 4: four(1);
case 5: five(1);
case 6: six(1);
case 7: seven(1);
case 8: eight(1);
case 9: nine(1);
case 10: zero(1);
}
switch (y){
case 1: one(2);
case 2: two(2);
case 3: three(2);
case 4: four(2);
case 5: five(2);
case 6: six(2);
case 7: seven(2);
case 8: eight(2);
case 9: nine(2);
case 10: zero(2);
}

 


void one(int d)
if (d==1)
{ digitalWrite(0,Low)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,Low)
digitalWrite(4,Low)
digitalWrite(5,Low)
digitalWrite(6,Low);

}else if (d==2)
{digitalWrite(0,Low)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,Low)
digitalWrite(4,Low)
digitalWrite(5,Low)
digitalWrite(6,Low);}
}

void two(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,High)
digitalWrite(2,Low)
digitalWrite(3,High)
digitalWrite(4,High)
digitalWrite(5,Low)
digitalWrite(6,High)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,High)
digitalWrite(9,Low)
digitalWrite(10,High)
digitalWrite(11,High)
digitalWrite(12,Low)
digitalWrite(13,High)}
}

void three(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,High)
digitalWrite(4,Low)
digitalWrite(5,Low)
digitalWrite(6,High)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,High)
digitalWrite(9,High)
digitalWrite(10,High)
digitalWrite(11,Low)
digitalWrite(12,Low)
digitalWrite(13,High)}
}

void four(int d)
{if d==1
{ digitalWrite(0,Low)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,Low)
digitalWrite(4,Low)
digitalWrite(5,High)
digitalWrite(6,High)

}else if d==2
{digitalWrite(7,Low)
digitalWrite(8,High)
digitalWrite(9,High)
digitalWrite(10,Low)
digitalWrite(11,Low)
digitalWrite(12,High)
digitalWrite(13,High)}
}

void five(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,Low)
digitalWrite(2,High)
digitalWrite(3,High)
digitalWrite(4,Low)
digitalWrite(5,High)
digitalWrite(6,High)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,Low)
digitalWrite(9,High)
digitalWrite(10,High)
digitalWrite(11,Low)
digitalWrite(12,High)
digitalWrite(13,High)}
}

void six(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,Low)
digitalWrite(2,High)
digitalWrite(3,High)
digitalWrite(4,High)
digitalWrite(5,High)
digitalWrite(6,High)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,Low)
digitalWrite(9,High)
digitalWrite(10,High)
digitalWrite(11,High)
digitalWrite(12,High)
digitalWrite(13,High)}
}

void seven(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,Low)
digitalWrite(4,Low)
digitalWrite(5,Low)
digitalWrite(6,Low)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,High)
digitalWrite(9,High)
digitalWrite(10,Low)
digitalWrite(11,Low)
digitalWrite(12,Low)
digitalWrite(13,Low)}
}

void eight(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,High)
digitalWrite(4,High)
digitalWrite(5,High)
digitalWrite(6,High)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,High)
digitalWrite(9,High)
digitalWrite(10,High)
digitalWrite(11,High)
digitalWrite(12,High)
digitalWrite(13,High)}
}

void nine(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,Low)
digitalWrite(4,Low)
digitalWrite(5,High)
digitalWrite(6,High)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,High)
digitalWrite(9,High)
digitalWrite(10,Low)
digitalWrite(11,low)
digitalWrite(12,High)
digitalWrite(13,High)}
}

void zero(int d)
{if d==1
{ digitalWrite(0,High)
digitalWrite(1,High)
digitalWrite(2,High)
digitalWrite(3,High)
digitalWrite(4,High)
digitalWrite(5,High)
digitalWrite(6,Low)

}else if d==2
{digitalWrite(7,High)
digitalWrite(8,High)
digitalWrite(9,High)
digitalWrite(10,High)
digitalWrite(11,High)
digitalWrite(12,High)
digitalWrite(13,Low)}
}

One problem (feature) is that your switch statements have no breaks, so if you jump to 5, lets say, all the functions below will be called, too. If thatis what you want, fine, otherwise you need a break after every function call. It is also good programming practice to include the default: case to add some error handling.

Incorrect Syntax = Compiler Errors.

What compiler errors are you seeing when you try to compile it?

I believe that the code I have it correct

Have you even tried to compile it yet?

I have been told by my proffessor that my syntax is wrong in many places

many places is right.

For a start, C statements are terminated with a semicolon. You need a lot of them.
The conditional part of an 'if' statement must be enclosed in parentheses.

Once you get rid of all the syntax errors, use the Tools|Auto Format menu to reformat the code into a more readable form.

Pete

aspick:
I have been told by my proffessor that my syntax is wrong in many places

He's obviously right - that doesn't even compile, does it?

The use of if/else if in the output functions is redundant, and it would only take a tiny effort to convert those dozens of lines of output code to a few constant declarations defining the segments on for each digit value and defining which pins correspond to which segments for each display digit, and some common code to output the set of segments states to a specified digit.

You could do with testing this code, too:

y=number%10;
x=(number/10)-y;

Once you get it working, note that it will produce numbers in the range 0 - 9 not 1 - 10 so your switch cases need correcting, and you need a break after each case.

The variables pin0 .. pin13 are (a) pointless, because the names tell us nothing more than the original number itself did, and (b) should be constants not variables.

I can see this is just an early project for you and although it's got quite a lot of issues at the moment I'm sure you'll soon get the hang of things, but I suggest that instead of writing the whole thing in one go and then wonder why it isn't working, you would be better off building up your sketch in small increments and test each part as you go. Is your analog read returning the values you expect? Can you convert the return value into two digits correctly? Can you output the digits 0 - 9 in the first position, and in the seconds position? Finally, can you add all those functions together into a working sketch?

During testing you'll find Serial.println statements hugely useful to let you see what's going on inside the Arduino, so you should consider leaving the serial pins (presumably 0 & 1) free so that the serial port works and connect those segments to other pins instead.

Hi aspick,

There are a few things wrong that I can see.

Like KeithRB said, you need to add breaks in your switch statements, otherwise they will all be executed one after the other.

switch (x){
case 1: one(1); break;
case 2: two(1); break:
case 3: three(1); break;
...

Secondly, you are missing semicolons in a number of places. It should look like this:

digitalWrite(1,High);
digitalWrite(2,High);
digitalWrite(3,Low);
digitalWrite(4,Low);

Thirdly, you need to add comments and indent your code! Otherwise, it is very difficult to read.

void loop() {
    sensorvalue=analogRead(A2);  // read sensor
    number=map(sensorvalue,0,1023,0,99); // convert sensor value to a number in he range 0-99
    y=number%10;  // get first digit
    x=(number/10)-y;  // get second digit
    switch (x){
        case 1: 
            one(1);
            break;
...

Also, I really can't tell what you are trying to do with your x= and y= lines. Are you trying to get the 1st and 2nd digits? I'm not sure that your code does that.

I suggest that you get a C programming book and review the syntax section. Programming can be fun, but it takes some work!

Pat.