Redefinition of void setup?

C:\Users_\Documents\Arduino\sketch_aug20c\New_tab_1.ino: In function 'void setup()':
New_tab_1:4:6: error: redefinition of 'void setup()'
void setup(){
^~~~~
C:\Users_
\Documents\Arduino\sketch_aug20c\sketch_aug20c.ino:8:6: note: 'void setup()' previously defined here
void setup()
^~~~~
C:\Users_\Documents\Arduino\sketch_aug20c\New_tab_1.ino: In function 'void loop()':
New_tab_1:9:6: error: redefinition of 'void loop()'
void loop(){
^~~~
C:\Users_
\Documents\Arduino\sketch_aug20c\sketch_aug20c.ino:18:6: note: 'void loop()' previously defined here
void loop()
^~~~
exit status 1
redefinition of 'void setup()'

I dont understand what the problem is with this.
Here is my code:

#include<Servo.h>
Servo servo;

int x_axis;

int servo_val;

void setup()

{

pinMode(A0,INPUT);

servo.attach(10);

}

void loop()

{

x_axis=analogRead(A0);

servo_val=map(x_axis,0,1023,0,180);

servo.write(servo_val);

}

NEW TAB 1

int Parachute=analogRead(A0);


void setup(){
pinMode(2,LOW);
  
}

void loop(){
if( Parachute=0 ){
digitalWrite(2,HIGH);  
  }
}

You apparently have two .ino files in you sketch. When they are compiled they copied into a single file which results in duplicate definitions - just like the error messages tell you.

As your topic does not relate directly to the installation or operation of the IDE it has been moved to the Programming Questions category of the forum

You have 2 tabs in the IDE, each with a setup() and loop() function. The code in both tabs will be compiled together by the IDE and you cannot have more than one function with the same name in the combined sketch (not quite true but applicable here)

Can you see the problem ?

I solved the problem. I switched the code from New tab 1 over to the original tab. Thanks for the help.

Presumably you deleted the original code in the main tab first

If you want to see, here is my new code

#include<Servo.h>
Servo servo;
int Parachute=analogRead(A0);
int x_axis;

int servo_val;

void setup(){
pinMode(2,LOW);


pinMode(A0,INPUT);

servo.attach(10);

}

void loop(){
if( int parachute = 0)
digitalWrite(2,HIGH);



x_axis=analogRead(A0);

servo_val=map(x_axis,0,1023,0,180);

servo.write(servo_val);

}

I can see a few problems with it

  • the Parachute variable is not the same as the parachute variable
  • What is pinMode(2, LOW); intended to do ?
  • if (int parachute = 0) what do you think this does ?

The code in parentheses declares a new integer variable named parachute and sets it to zero, which is also the result of the expression.

So the if statement becomes if (0) and the digitalWrite statement will never be executed.