Go Down

Topic: Compile error "redeclared as different kind of symbol" (Read 13334 times) previous topic - next topic

JoaoAnacleto

Oct 23, 2018, 03:57 pm Last Edit: Oct 24, 2018, 03:43 am by Coding Badly
Hello, I'm having trouble completing this code for the arduino due.
"'volatile int P' redeclared as different kind of symbol"
"'volatile int V [2]' redeclared the different kind of symbol '.
Does anyone have any idea why?

Code: [Select]

//comments in portuguese

volatile String Operasao = "M";
volatile int P = 0;
volatile int V[2] = {0,0};
volatile String Posisao;

void setup() {

Serial.begin(9600);

attachInterrupt(digitalPinToInterrupt (2), A, HIGH);
attachInterrupt(digitalPinToInterrupt (3), B, HIGH);
attachInterrupt(digitalPinToInterrupt (4), C, HIGH);
attachInterrupt(digitalPinToInterrupt (5), D, HIGH);
attachInterrupt(digitalPinToInterrupt (6), E, HIGH);
attachInterrupt(digitalPinToInterrupt (7), f, HIGH);
attachInterrupt(digitalPinToInterrupt (8 ), G, HIGH);
attachInterrupt(digitalPinToInterrupt (9), H, HIGH);
attachInterrupt(digitalPinToInterrupt (10), I, HIGH);
attachInterrupt(digitalPinToInterrupt (11), J, HIGH);
attachInterrupt(digitalPinToInterrupt (12), K, HIGH);
attachInterrupt(digitalPinToInterrupt (13), L, HIGH);
attachInterrupt(digitalPinToInterrupt (21), M, HIGH);
attachInterrupt(digitalPinToInterrupt (22), N, HIGH);
attachInterrupt(digitalPinToInterrupt (23), O, HIGH);
attachInterrupt(digitalPinToInterrupt (24), P, HIGH);
attachInterrupt(digitalPinToInterrupt (25), Q, HIGH);
attachInterrupt(digitalPinToInterrupt (26), R, HIGH);
attachInterrupt(digitalPinToInterrupt (27), S, HIGH);
attachInterrupt(digitalPinToInterrupt (28), T, HIGH);
attachInterrupt(digitalPinToInterrupt (29), U, HIGH);
attachInterrupt(digitalPinToInterrupt (30), V, HIGH);
attachInterrupt(digitalPinToInterrupt (31), W, HIGH);
attachInterrupt(digitalPinToInterrupt (32), X, HIGH);
attachInterrupt(digitalPinToInterrupt (33), Y, HIGH);
attachInterrupt(digitalPinToInterrupt (34), Z, HIGH);
attachInterrupt(digitalPinToInterrupt (35), AA, HIGH);
attachInterrupt(digitalPinToInterrupt (36), AB, HIGH);
attachInterrupt(digitalPinToInterrupt (37), AC, HIGH);
attachInterrupt(digitalPinToInterrupt (38), AD, HIGH);
attachInterrupt(digitalPinToInterrupt (39), AE, HIGH);
attachInterrupt(digitalPinToInterrupt (40), AF, HIGH);
attachInterrupt(digitalPinToInterrupt (41), AG, HIGH);
attachInterrupt(digitalPinToInterrupt (42), AH, HIGH);
attachInterrupt(digitalPinToInterrupt (43), AI, HIGH);
attachInterrupt(digitalPinToInterrupt (44), AJ, HIGH);
attachInterrupt(digitalPinToInterrupt (45), AK, HIGH);
attachInterrupt(digitalPinToInterrupt (46), AL, HIGH);
attachInterrupt(digitalPinToInterrupt (47), AM, HIGH);
attachInterrupt(digitalPinToInterrupt (48), AN, HIGH);
attachInterrupt(digitalPinToInterrupt (49), AO, HIGH);
attachInterrupt(digitalPinToInterrupt (50), AP, HIGH);
attachInterrupt(digitalPinToInterrupt (51), AQ, HIGH);
attachInterrupt(digitalPinToInterrupt (52), AR, HIGH);
attachInterrupt(digitalPinToInterrupt (53), AS, HIGH);
}  


void A() { // manual
Operasao = "M"
}
void B() { // automatico
Operasao = "A"
}
void C() { // cima
P = P+1;
}
void D() { // baixo
if (P>0){
P = P-1;  
}
}
void E() { // Parametros
P = 0;
Posisao = "IN"+ P;
}
void f() { // injeção
if (Operasao = "A"){
P = 0;
Posisao = "IN"+ P;
}
}
void G() { // dosagem
if (Operasao = "A"){
P = 0;
Posisao = "DO"+ P;
}
}
void H() { // descompressão
if (Operasao = "A"){
P = 0;
Posisao = "DE"+ P;
}
}
void I() { // ciclo
P = 0;
Posisao = "CI"+ P ;
}
void J() { // temperatura
P = 0;
Posisao = "TE"+ P;
}
void K() { // abertura
if (Operasao = "A"){
P = 0;
Posisao = "AB"+ P;
}
}
void L() { // fechamento
if (Operasao = "A"){
P = 0;
Posisao = "FE"+ P;
}
}
void fe() { // paramentros + injeção
P = 0;
Posisao = "IN"+ P;
}
void ge() { // paramentros + dosagem
P = 0;
Posisao = "DO"+ P;
}
void he() { // paramentros + descompressão
P = 0;
Posisao = "DE"+ P;
}
void ke() { // paramentros + abertura
P = 0;
Posisao = "AB"+ P;
}
void le() { // paramentros + fechamento
P = 0;
Posisao = "FE"+ P;
}


void M() { // editar
  Ed = Ed + 1;
}
void N() { // Entra
 Serial.println(Posisao);
 Serial.print(",");
 Serial.print(Ed);
 Serial.print(",");
 Serial.print(V[1]);
 Serial.print(V[2]);
// EXEMPLO DE  SAIDA : DO3,2,30
}

                                    // TECLADO NUMERICO
                                    void O() { // 1
                                    V[1] = V[2];
                                    V[2] = 1;
                                    }
                                    void P() { // 2
                                      V[1] = V[2];
                                      V[2] = 2;
                                    }
                                    void Q() { // 3
                                      V[1] = V[2];
                                      V[2] = 3;
                                    }
                                    void R() { // 4
                                      V[1] = V[2];
                                      V[2] = 4;
                                    }
                                    void S() { // 5
                                      V[1] = V[2];
                                      V[2] = 5;
                                    }
                                    void T() { // 6
                                      V[1] = V[2];
                                      V[2] = 6;
                                    }
                                    void U() { // 7
                                      V[1] = V[2];
                                      V[2] = 7;
                                    }
                                    void V() { // 8
                                      V[1] = V[2];
                                      V[2] = 8;
                                    }
                                    void W() { // 9
                                      V[1] = V[2];
                                      V[2] = 9;
                                    }
                                    void X() { // 0
                                      V[1] = V[2];
                                      V[2] = 0;
                                    }

void Y() { // Cancela edição
Ed = 0;
}




//-----------------------------------------------------------------------------//----------------------------------------------//---------------------------------------------------------------------




void Z() {
}
void AA() {
}
void AB() {
}
void AC() {
}
void AD() {
}
void AE() {
}
void AF() {
}
void AG() {
}
void AH() {
}
void AI() {
}
void AJ() {
}
void AK() {
}
void AL() {
}
void AM() {
}
void AN() {
}
void AO() {
}
void AP() {
}
void AQ() {
}
void AR() {
}
void AS() {
}
void loop(){
  
}



Moderator edit: [code] [/code] tags added.

UKHeliBob

The problem is probably caused by the fact that P and V are already defined by the system.  Try changing the names

Why are you using such an enormous number of interrupts ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

johnwasser

If you looked at the error messages that showed up in the text box below your sketch you would see the problem:
Code: [Select]















sketch_oct20a:183: error: 'void P()' redeclared as different kind of symbol
 void P()   // 2
        ^
/Users/john/Documents/Arduino/sketch_oct20a/sketch_oct20a.ino:4:14: note: previous declaration 'volatile int P'
 volatile int P = 0;
              ^
sketch_oct20a:213: error: 'void V()' redeclared as different kind of symbol
 void V()   // 8
        ^
/Users/john/Documents/Arduino/sketch_oct20a/sketch_oct20a.ino:5:14: note: previous declaration 'volatile int V [2]'
 volatile int V[2] = {0, 0};
              ^



You have an int variable named 'P' and a function named 'P'.
You have an int array named 'V' and a function named 'V'.
Fix those, and then work on all the other problems, like missing ';'s.


Adding an integer to a string constant doesn't do what you might expect, although if you set the integer you add is zero it should not be damaging.
Code: [Select]
void E()   // Parametros
{
  P = 0;
  Posisao = "IN" + P;
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

JoaoAnacleto

#3
Oct 23, 2018, 06:33 pm Last Edit: Oct 24, 2018, 03:44 am by Coding Badly
Thanks for the help John and helibob. I am a beginner in Arduino and did not know how to find the error through the error notification window.

responding bob, I'm using interrupts to monitor a keyboard. I opted for the interrupt instead of digitalRead because it has a faster response, but for this application really does not make much difference, any recommendation against using this number of interrupts?

here is the compiled code:
(I had to remove the volatile strings)



Code: [Select]


String Operasao = "M";
volatile int Pi = 0;
volatile int V[2] = {0,0};
String Posisao;
volatile int Ed = 0;
void setup() {
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt (2), A, HIGH);
attachInterrupt(digitalPinToInterrupt (3), B, HIGH);
attachInterrupt(digitalPinToInterrupt (4), C, HIGH);
attachInterrupt(digitalPinToInterrupt (5), D, HIGH);
attachInterrupt(digitalPinToInterrupt (6), E, HIGH);
attachInterrupt(digitalPinToInterrupt (7), f, HIGH);
attachInterrupt(digitalPinToInterrupt (8), G, HIGH);
attachInterrupt(digitalPinToInterrupt (9), H, HIGH);
attachInterrupt(digitalPinToInterrupt (10), I, HIGH);
attachInterrupt(digitalPinToInterrupt (11), J, HIGH);
attachInterrupt(digitalPinToInterrupt (12), K, HIGH);
attachInterrupt(digitalPinToInterrupt (13), L, HIGH);
attachInterrupt(digitalPinToInterrupt (21), M, HIGH);
attachInterrupt(digitalPinToInterrupt (22), N, HIGH);
attachInterrupt(digitalPinToInterrupt (23), O, HIGH);
attachInterrupt(digitalPinToInterrupt (24), P, HIGH);
attachInterrupt(digitalPinToInterrupt (25), Q, HIGH);
attachInterrupt(digitalPinToInterrupt (26), R, HIGH);
attachInterrupt(digitalPinToInterrupt (27), S, HIGH);
attachInterrupt(digitalPinToInterrupt (28), T, HIGH);
attachInterrupt(digitalPinToInterrupt (29), U, HIGH);
attachInterrupt(digitalPinToInterrupt (30), Vv, HIGH);
attachInterrupt(digitalPinToInterrupt (31), W, HIGH);
attachInterrupt(digitalPinToInterrupt (32), X, HIGH);
attachInterrupt(digitalPinToInterrupt (33), Y, HIGH);
attachInterrupt(digitalPinToInterrupt (34), Z, HIGH);
attachInterrupt(digitalPinToInterrupt (35), AA, HIGH);
attachInterrupt(digitalPinToInterrupt (36), AB, HIGH);
attachInterrupt(digitalPinToInterrupt (37), AC, HIGH);
attachInterrupt(digitalPinToInterrupt (38), AD, HIGH);
attachInterrupt(digitalPinToInterrupt (39), AE, HIGH);
attachInterrupt(digitalPinToInterrupt (40), AF, HIGH);
attachInterrupt(digitalPinToInterrupt (41), AG, HIGH);
attachInterrupt(digitalPinToInterrupt (42), AH, HIGH);
attachInterrupt(digitalPinToInterrupt (43), AI, HIGH);
attachInterrupt(digitalPinToInterrupt (44), AJ, HIGH);
attachInterrupt(digitalPinToInterrupt (45), AK, HIGH);
attachInterrupt(digitalPinToInterrupt (46), AL, HIGH);
attachInterrupt(digitalPinToInterrupt (47), AM, HIGH);
attachInterrupt(digitalPinToInterrupt (48), AN, HIGH);
attachInterrupt(digitalPinToInterrupt (49), AO, HIGH);
attachInterrupt(digitalPinToInterrupt (50), AP, HIGH);
attachInterrupt(digitalPinToInterrupt (51), AQ, HIGH);
attachInterrupt(digitalPinToInterrupt (52), AR, HIGH);
attachInterrupt(digitalPinToInterrupt (53), AS, HIGH);
}  


void A() { // manual
Operasao = "M";
}
void B() { // automatico
Operasao = "A";
}
void C() { // cima
Pi = Pi+1;
}
void D() { // baixo
if (Pi>0){
Pi = Pi-1;  
}
}
void E() { // Parametros
Pi = 0;
Posisao = "IN";
}
void f() { // injeção
if (Operasao = "A"){
Pi = 0;
Posisao = "IN";
}
}
void G() { // dosagem
if (Operasao = "A"){
Pi = 0;
Posisao = "DO";
}
}
void H() { // descompressão
if (Operasao = "A"){
Pi = 0;
Posisao = "DE";
}
}
void I() { // ciclo
Pi = 0;
Posisao = "CI";
}
void J() { // temperatura
Pi = 0;
Posisao = "TE";
}
void K() { // abertura
if (Operasao = "A"){
Pi = 0;
Posisao = "AB";
}
}
void L() { // fechamento
if (Operasao = "A"){
Pi = 0;
Posisao = "FE";
}
}
void fe() { // paramentros + injeção
Pi = 0;
Posisao = "IN";
}
void ge() { // paramentros + dosagem
Pi = 0;
Posisao = "DO";
}
void he() { // paramentros + descompressão
Pi = 0;
Posisao = "DE";
}
void ke() { // paramentros + abertura
Pi = 0;
Posisao = "AB";
}
void le() { // paramentros + fechamento
Pi = 0;
Posisao = "FE";
}


void M() { // editar
  Ed = Ed + 1;
}
void N() { // Entra
 Serial.println(Posisao);
 Serial.print(Pi);
 Serial.print(Ed);
 Serial.print(V[1]);
 Serial.print(V[2]);
// EXEMPLO DE  SAIDA : DO3230
}

                                    // TECLADO NUMERICO
                                    void O() { // 1
                                    V[1] = V[2];
                                    V[2] = 1;
                                    }
                                    void P() { // 2
                                      V[1] = V[2];
                                      V[2] = 2;
                                    }
                                    void Q() { // 3
                                      V[1] = V[2];
                                      V[2] = 3;
                                    }
                                    void R() { // 4
                                      V[1] = V[2];
                                      V[2] = 4;
                                    }
                                    void S() { // 5
                                      V[1] = V[2];
                                      V[2] = 5;
                                    }
                                    void T() { // 6
                                      V[1] = V[2];
                                      V[2] = 6;
                                    }
                                    void U() { // 7
                                      V[1] = V[2];
                                      V[2] = 7;
                                    }
                                    void Vv() { // 8
                                      V[1] = V[2];
                                      V[2] = 8;
                                    }
                                    void W() { // 9
                                      V[1] = V[2];
                                      V[2] = 9;
                                    }
                                    void X() { // 0
                                      V[1] = V[2];
                                      V[2] = 0;
                                    }

void Y() { // Cancela edição
Ed = 0;
}




//-----------------------------------------------------------------------------//----------------------------------------------//---------------------------------------------------------------------




void Z() {
}
void AA() {
}
void AB() {
}
void AC() {
}
void AD() {
}
void AE() {
}
void AF() {
}
void AG() {
}
void AH() {
}
void AI() {
}
void AJ() {
}
void AK() {
}
void AL() {
}
void AM() {
}
void AN() {
}
void AO() {
}
void AP() {
}
void AQ() {
}
void AR() {
}
void AS() {
}
void loop(){
  
}




Moderator edit: [code] [/code] tags added.

UKHeliBob

Quote
any recommendation against using this number of interrupts?
Why make things complicated by using interrupts ?

Put the pin numbers to be monitored in an array and iterate through it and use digitalRead() to determine their state.  If the state is HIGH then act on it.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up