undefined reference to`setup'

I am working on a 2 button calculator and there is an error message in the compiler saying:

undefined reference to `setup'

(I am using Arduino IDE 2.0)

This is the code that I think is buggy:

void setup(bool startLoadingScreen = true) {
  // Start the LCD:
  lcd.begin();
  lcd.backlight();
  lcd.clear();
  // Start the Serial Monitor for debugging:
  Serial.begin(9600);
  // Create the custom characters for the LCD:
  lcd.createChar(0, MidEmpty);
  lcd.createChar(1, LeftEmpty);
  lcd.createChar(2, RightEmpty);
  lcd.createChar(3, AnyFull);
  lcd.createChar(4, Divide);
  // Load the loading screen if we want to:
  if (startLoadingScreen = true) {
    LoadingScreen();
  }
  // Define the button pins:
  pinMode(Left, INPUT_PULLUP);
  pinMode(Right, INPUT_PULLUP);
  // Display the Calculator interface:
  lcd.setCursor(5, 1);
  lcd.print("Calculator");
  lcd.setCursor(2, 3);
  lcd.print("+");
  lcd.setCursor(6, 3);
  lcd.print("-");
  lcd.setCursor(9, 3);
  lcd.print("x");
  lcd.setCursor(13, 3);
  lcd.write(4);
  lcd.setCursor(17, 3);
  lcd.print("^");
  lcd.setCursor(2, 3);
  lcd.blink();
}

--265 lines later--

for (int i = 0; i < 16; i++) {
      if (i >= 9 and opDigits[i] != 0) {
        lcd.clear();
        lcd.home();
        lcd.print("An Error Occurred:");
        lcd.setCursor(0, 2);
        lcd.print("opDigits.length()>9");
        delay(10000);
        setup(false);
      }
      opNumber += startDigits[i];
    }
    OperationOutput = startNumber + opNumber;
    if (OperationOutput > 18446744073709551615) {
        lcd.clear();
        lcd.home();
        lcd.print("An Error Occurred:");
        lcd.setCursor(0, 2);
        lcd.print("OperationOutput>");
        lcd.setCursor(0, 3);
        lcd.print("18446744073709551615");
        delay(10000);
        setup(false);
      }

    lcd.setCursor((10 - (int64String(OperationOutput).length() / 2)), 2);
    lcd.print(int64String(OperationOutput));
    lcd.setCursor(0, 3);
    while (digitalRead(Left) == HIGH and digitalRead(Right) == HIGH) {
      lcd.print("Press A Button To Ex");
      delay(1000);
      lcd.setCursor(0, 3);
      lcd.print("ress A Button To Exi");
      delay(1000);
      lcd.setCursor(0, 3);
      lcd.print("ess A Button To Exit");
      delay(1000);
      lcd.setCursor(0, 3);
    }
    setup(false);
  }
  inOperation = false;
}

Note that this is my first forum post, I have never posted before!

Files:

Calculator.ino (9.15 KB)

CustomChars.h (553 Bytes)

You can't use the name "setup" - without arguments - for one of your own functions: void setup() and void loop() are reserved words. Your primary sketch must contain those two (without any parameters!) and they will be executed right after the Arduino starts. Once for setup(), loop() will run over and over again.

(Edit: added "without arguments" for clarity).

Absolute minumum sketch:

void setup() {
 // runs once
}

void loop() {
  // repeated endlessly
}

Erik_Baas:
You can't use the name "setup" for one of your own functions: void setup() and void loop() are reserved words.

Ummmm... No. It is perfectly OK to define your own setup and loop functions that take arguments. setup and loop are NOT reserved words. But you must also define the no-argument functions, or the link will fail.

RayLivingston:
It is perfectly OK to define your own setup and loop functions that take arguments.

Which is why I wrote void setup() and void loop(), so indeed without arguments. Trying to keep it simple, you know.

void setup()
{
  setup(true);
}

void setup(bool startLoadingScreen) {
  // Start the LCD:
  lcd.begin();
  lcd.backlight();
  etc...
if (startLoadingScreen = true) {

Oops.

Remember
= for assignment
== for comparison

... and comparison with true or false is unnecessary.

Also, I have forgotten to mention that this is for the Arduino Mega 2560 board if you want to compile.
I also used the Int64String library that you can find in the library manager.

Oh and, if you have any suggestions, please reply with the suggestion.

Thanks!

if you have any suggestions, please reply with the suggestion.

Have you noted the replies already posted ?

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