Error messages: 'void setup()' previously defined here void setup() { ^

I am a beginner level programmer and I was trying to upload my code when I got these error messages.

Command failed: /var/folders/f6/xgl4fkbs4sq34px5fkx9v68c0000gn/T//build1437767220962/Lamp.cpp: In function 'void setup()': /var/folders/f6/xgl4fkbs4sq34px5fkx9v68c0000gn/T//build1437767220962/Lamp.cpp:51:6: error: redefinition of 'void setup()' void setup(){ ^ /var/folders/f6/xgl4fkbs4sq34px5fkx9v68c0000gn/T//build1437767220962/Lamp.cpp:18:6: error: 'void setup()' previously defined here void setup() { ^ /var/folders/f6/xgl4fkbs4sq34px5fkx9v68c0000gn/T//build1437767220962/Lamp.cpp: In function 'void loop()': /var/folders/f6/xgl4fkbs4sq34px5fkx9v68c0000gn/T//build1437767220962/Lamp.cpp:58:6: error: redefinition of 'void loop()' void loop(){ ^ /var/folders/f6/xgl4fkbs4sq34px5fkx9v68c0000gn/T//build1437767220962/Lamp.cpp:24:6: error: 'void loop()' previously defined here void loop() { ^

I looked back on my code and noticed that I expressed the function "void setup () {} and void loop() {}", so surely nothing could be wrong. Is this an Arduino IDE problem?

Here is the code from the Arduino projects book that I wanted to upload:

const int greenledpin = 9;
const int redledpin = 11;
const int blueledpin = 10;
const int redsensorpin = A0;
const int greensensorpin = A1;
const int bluesensorpin = A2;
int redvalue = 0;
int greenvalue = 0;
int bluevalue = 0;
int redsensorvalue = 0;
int bluesensorvalue = 0;
int greensensorvalue = 0;
void setup() {
Serial.begin(9600);
pinMode(greenledpin, OUTPUT);
pinMode(redledpin, OUTPUT);
pinMode(blueledpin, OUTPUT);
}
void loop() {
redsensorvalue = analogRead(redsensorpin);
delay(5);
greensensorvalue = analogRead(greensensorpin);
delay(5);
bluesensorvalue = analogRead(bluesensorpin);
Serial.print("Raw Sensor Values \t Red: ");
Serial.print(redsensorvalue);
Serial.print("\t Green: ");
Serial.print(greensensorvalue);
Serial.print("\t Blue: ");
Serial.println(bluesensorvalue);
redvalue = redsensorvalue/4;
greenvalue = greensensorvalue/4;
bluevalue = bluesensorvalue/4;
Serial.print("Mapped Sensor Values \t Red: ");
Serial.print(redvalue);
Serial.print("\t green: ");
Serial.print(greenvalue);
Serial.print("\t Blue: ");
Serial.print(bluevalue);
analogWrite(greenledpin, greenvalue);
analogWrite(blueledpin, bluevalue);
analogWrite(redledpin, redvalue);
}

I would appreciate an explanation for this error; Thankyou!

Please post all your code.
Use code tags.

Is this what you are talking about Awol?

const int greenledpin = 9;
const int redledpin = 11;
const int blueledpin = 10;
const int redsensorpin = A0;
const int greensensorpin = A1;
const int bluesensorpin = A2;
int redvalue = 0;
int greenvalue = 0;
int bluevalue = 0;
int redsensorvalue = 0;
int bluesensorvalue = 0;
int greensensorvalue = 0;
void setup() {
    Serial.begin(9600);
    pinMode(greenledpin, OUTPUT);
    pinMode(redledpin, OUTPUT);
    pinMode(blueledpin, OUTPUT);
}
void loop() {
    redsensorvalue = analogRead(redsensorpin);
    delay(5);
    greensensorvalue = analogRead(greensensorpin);
    delay(5);
    bluesensorvalue = analogRead(bluesensorpin);
    Serial.print("Raw Sensor Values \t Red: ");
    Serial.print(redsensorvalue);
    Serial.print("\t Green: ");
    Serial.print(greensensorvalue);
    Serial.print("\t Blue: ");
    Serial.println(bluesensorvalue);
    redvalue = redsensorvalue/4;
    greenvalue = greensensorvalue/4;
    bluevalue = bluesensorvalue/4;
    Serial.print("Mapped Sensor Values \t Red: ");
    Serial.print(redvalue);
    Serial.print("\t green: ");
    Serial.print(greenvalue);
    Serial.print("\t Blue: ");
    Serial.print(bluevalue);
    analogWrite(greenledpin, greenvalue);
    analogWrite(blueledpin, bluevalue);
    analogWrite(redledpin, redvalue);
}

When I compile your code, I get only one "error":

Binary sketch size: 5,876 bytes (of a 258,048 byte maximum)


That's the "error" most people try to get.

Paul S,
I believe something is wrong with the arduino ide. I am getting about 6 errors. I'm on a mac osx os. So if there is anything to changes in the arduino ide's preferences please let me know. :slight_smile:

Why Not? fix what PaulS pointed out first??...

Doc

What version of the IDE do you have? What type of Arduino are you compiling for? Is this the only file in your project?

Docedison:
Why Not? fix what PaulS pointed out first??...

Doc

What I pointed out was that on my system, there is nothing wrong with OPs code. What did you want OP to fix?

Nick Gammon,
I appreciate your time. I am running Arduino IDE version 0.0.2 Alpha on a MAC OSX operating system.
I have one other sketch that I have created on the IDE. I hope this info will help you.

I am running Arduino IDE version 0.0.2 Alpha

What? That is not even in the neighborhood of a correct version number.

LMS228:
I appreciate your time. I am running Arduino IDE version 0.0.2 Alpha on a MAC OSX operating system.

Where'd you get that from? Try getting a more up-to-date version: https://www.arduino.cc/en/Main/Software

I have one other sketch that I have created on the IDE. I hope this info will help you.

Yes, but in your project? How many tabs can you see in the IDE?

FACEPALM Now I know why we are called noobs. I wonder why that version is on the Arduino site. Problem solved for now. Ill keep this forum posted in case it persists. Thankyou Nick Gammon. Because im new to the Arduino scene I didn't even realize what version of Arduino IDE I should use so I downloaded a terrible version FACEPALM.

I think hes using the new ArduioStudio IDE. Its currently on v0.0.3 Alpha. http://labs.arduino.org/Arduino+Studio

I just started using it myself, being new to Arduno, why not check out the new tools? This seems to be a common problem when having multiple sketchs open simultaneously in ArduioStudio. Even closing all sketches, exiting the program and then coming back to the sketch does not seem to fix it.

Going to use the mature IDE now and wait for the next version of Studio.

I think he's using the new ArduioStudio IDE. It's currently on v0.0.3 Alpha.

Well, that's confusing.

It is simple - you have two *.ino files in your directory. If it tries to compile it takes both of them, just remove the second one or change its extension.

3 Likes

jviktes:
It is simple - you have two *.ino files in your directory. If it tries to compile it takes both of them, just remove the second one or change its extension.

You're about three years too late there.