Having trouble with void setup

I am having trouble with what Arduino wants. I have looked at other programs with the same void setup function and it works fine in other programs. The code is below with the error message. Any guidance much appreciated.

Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"

C:\Users\davec\Documents\Arduino\libraries\MyBuild\HelloWorld.ino: In function 'void setup()':

HelloWorld:41:9: error: redefinition of 'void setup()'

void setup(){

     ^~~~~

C:\Users\davec\Documents\Arduino\libraries\MyBuild\MyBuild.ino:17:8: note: 'void setup()' previously defined here

void setup(){

    ^~~~~

C:\Users\davec\Documents\Arduino\libraries\MyBuild\HelloWorld.ino: In function 'void loop()':

HelloWorld:46:6: error: redefinition of 'void loop()'

void loop() {

  ^~~~

C:\Users\davec\Documents\Arduino\libraries\MyBuild\MyBuild.ino:38:6: note: 'void loop()' previously defined here

void loop(){

  ^~~~

exit status 1

redefinition of 'void setup()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

/*
LiquidCrystal Library - Hello World

http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){

lcd.begin(16, 2);
}

void loop() {
lcd.print("Hello World");
delay(500);
lcd.clear();
delay(500);
}

Post your entire sketch, in code tags. You were told about it a year ago:

" But do please read the instructions, then go back and edit your post #7 to properly include the code.

Edit - "pencil" icon below the post."

You're missing declarations from the examples you linked to.

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

They might be used in your libraries so you can't just sub them in the one line. Try it the way the example showed and let us know.

That is incorrect. Such values are passed as numerical parameters to the LiquidCrystal class constructor. The class can not and should not know about variable identifiers in the user program.

1 Like

C:\Users\davec\Documents\Arduino\libraries\MyBuild\HelloWorld.ino: In function 'void setup()'

Just a thought: is it something about the folder structure?

READ the error messages! They tell EXACTLY what is going on. There are TWO .ino files in the same folder. They are being combined into one file, and compiled. The "extra" .ino file MUST be re-named to something other than .ino, or deleted entirely.

1 Like

The fact that the sketch is being built in the libraries folder is concerning too. Is it your intention to build a library, rather than a normal Arduino sketch?

Do you really think that Op wanted to write a library? And asking questions like this?

1 Like

Almost certainly not, but I didn't want to outright tell gentledave7 to move their sketch without at least finding out what they are actually trying to accomplish. Hopefully can help correct any misunderstandings that have put them in this situation.

You have two .ino files in your sketch directory: HelloWorld.ino and MyBuild.ino. The Arduino IDE will concatenate them, and you'll have a setup() from each one.

For the Arduino IDE, the sketch name should match the directory it is in, so you probably want to get rid of HelloWorld.ino

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.