Help , error : " redefinition of 'int val'

Good afternoon, I know the error is obvious but I would like you to help me solve it, I don’t know how to do it. I am trying to make a cart (l298n) with remote control that measures the temperature with lm35. This cart will be the data receiver (via nrfl2401).

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”

int val;
int tempPin = 1;
int LMotor=10;
int RMotor=9;
int val = 0;
int off = 0;
int reverse;
int forward;
int circle;
int turn;
int aheadY;
int turnX;

typedef struct{
float temp;
float pres_T;
float pres_P;

}B_t;

B_t server;

RF24 radio(A1,A2); // uint8_t _cepin, uint8_t _cspin
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup() {

pinMode (5,OUTPUT);
pinMode (6,OUTPUT);
pinMode (11,OUTPUT);
pinMode (12,OUTPUT);

pinMode(LMotor,OUTPUT);
pinMode(RMotor,OUTPUT);
pinMode(13,HIGH);

Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();

}

void loop() {

val = analogRead(tempPin);
float mv = ( val/1024.0)5000;
float cel = mv/10;
float farh = (cel
9)/5 + 32;

if( radio.available()) {
radio.read( &server, sizeof(server) );

Serial.print("server.temp = ");
Serial.println(server.temp);
Serial.println();
delay(3000);

reverse=pulseIn(4,HIGH);
aheadY =pulseIn(7,HIGH);
turnX = pulseIn(8,HIGH);
forward = map(aheadY, 1000,1882, 35, 255);

circle = map(turnX,1030,1889,-225,225);

turn = map(turnX, 1030,1889,-128,127);
turn = constrain(turn, -128,127);

if (circle < 0){

circle = -1 *circle;
}

if (reverse <1200 )
{

digitalWrite (5,LOW);
delay(1);
digitalWrite(6,HIGH);
delay(1);

digitalWrite (11,LOW);
delay(1);
digitalWrite(12,HIGH);
delay(1);
digitalWrite(13,LOW);

}
if (reverse>1200){
digitalWrite (6,LOW);
delay(1);
digitalWrite(5,HIGH);
delay(1);

digitalWrite (12,LOW);

delay(1);
digitalWrite(11,HIGH);
delay(1);
digitalWrite(13,HIGH);

}

if (forward < 60 && turn < -15){

digitalWrite (6,LOW);
delay(1);
digitalWrite(5,HIGH); //left rotaion
delay(1);

digitalWrite (11,LOW);
delay(1);
digitalWrite(12,HIGH);
analogWrite (LMotor,circle);
analogWrite (RMotor,circle);
Serial.print(" L rota");
}

if (forward < 60 && turn > 15){

digitalWrite (5,LOW);
delay(1);
digitalWrite(6,HIGH); //right rotaion
delay(1);

digitalWrite (12,LOW);
delay(1);
digitalWrite(11,HIGH);
analogWrite (LMotor,circle);
analogWrite (RMotor,circle);
Serial.print(" R rot");
}

//Serial.print(" aheadY “);
// Serial.print(aheadY);
//Serial.print(” turn ");
// Serial.print(turnX);

Serial.print(" forward “);
Serial.print(forward);
Serial.print(” Turn “);
Serial.print(turn);
Serial.print(” circle ");
Serial.print(circle);
// Serial.println(reverse);

if (forward > 60 &&turn >=-16 && turn <=16) // forward

{

analogWrite (LMotor,forward);
analogWrite (RMotor,forward);
Serial.print(" go forward");

}

if (forward <= 60 && turn >=-16 && turn <=16 )

{

analogWrite (LMotor,0); // no effect
analogWrite (RMotor,0);
Serial.print(" stop");

}

if (turn <=-15 && forward > 60) // forward left

{

analogWrite (LMotor,forward );
analogWrite (RMotor,0);
Serial.print(" forward left");

}

if (turn >=15 && forward > 60) // forward right

{

analogWrite (LMotor,0);
analogWrite (RMotor,forward );
Serial.print(" forward left");

}

Serial.println(" ");

}

Read this before posting.

Also, what is the error you are getting?

int val;
int tempPin = 1;
int LMotor=10;
int RMotor=9;
int val = 0;

right there.

TheMemberFormerlyKnownAsAWOL:

int val;

int tempPin = 1;
int LMotor=10;
int RMotor=9;
int val = 0;


right there.

Can you declare a variable twice?

delete line 1 in the code of mosalam. indeed double name in setup

shooter:
delete line 1 in the code of mosalam. indeed double name in setup

?

NOT for OP:

GolamMostafa:
Can you declare a variable twice?

Yes, you can declare a variable as many time as you want. But you can define it only once.

extern int val; //declare val
extern int val; //declare val
int val = 0; //define val

For OP:
Just delete the line int val;

I mainly wanted to combine 2 programming codes (one of the nrfl2401) and the other of the rc car (with l298n), but as you can see I realized that the int val and the int val = 0 are declared twice,
that's why I wanted someone to tell me how I can fix this

arduino_new:
NOT for OP:Yes, you can declare a variable as many time as you want. But you can define it only once.

extern int val; //declare val

extern int val; //declare val
int val = 0; //define val

Can the variables val be declared as follows:

int val;
int val;

or

int val;
int val = 0;

GolamMostafa:
Can the variables val be declared as follows:

int val;

int val;




or



int val;
int val = 0;

int val;

This is not a declaration though, this is a declaration AND definition of the variable.

arduino_new:

int val;

This is not a declaration though, this is a declaration AND definition of the variable.

Declaration and definition bear different meanings in social context; in programming context, they are interchangeable which I have seen in many writings.

In the very early school of programming, we have heard our tutors saying: you have to declare the variable first, and then you define it; else, it will be defined by program codes during run time.

Definition implies declaration; sometimes, declaration does imply definition.

jesusdlc12:
I mainly wanted to combine 2 programming codes (one of the nrfl2401) and the other of the rc car (with l298n), but as you can see I realized that the int val and the int val = 0 are declared twice,
that’s why I wanted someone to tell me how I can fix this

Use a different name for one of them and change the name to the new one in the program, but only where it is relevant