IDE threw an error after only adding one line

hello, I got this error after adding a line to the setup function:
updatearmed:1:15: error: a function-definition is not allowed here before '{' token
void armedup(){
^
updatearmed:8:1: error: expected '}' at end of input
}
^
exit status 1
'qtestcon' was not declared in this scope

this repeats several times for every function.


//#include <avr/wdt.h>
#include <Wire.h>
#include <AsyncTimer.h>
#include <Adafruit_Fingerprint.h>
AsyncTimer t(1);


SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 7, d7 = 6;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int lastcounter;
String options[] = {"add", "remove", "exit"};
#define testdelay 750
#define testr 240
#define testdis 50
bool printing;
int printc;
int counter = 0;
bool counteron = false;
bool armed = false;
bool showa = false;
bool inmenu = false;
int items = 0 ;
bool waiting = true;
bool curentarmed;
int com, lcom;
int testcounter, ltestcounter;
bool shouldtest = false;
bool first = true;
bool autotest = true;
bool startsysarmed;
bool testing = false;
int systcounter;
int lsystcounter;
bool lasttest;
bool authenticated = false;
int a, la;
#include <EEPROM.h>
void setup()
{
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);
  analogWrite(A5, 255);
  analogWrite(A4, 0);
  //wdt_enable(WDTO_8S);
  while (qtestcon() == false || lcdtest() == false ) {
    lcd.clear();
    lcd.print(F("waiting"));
    if (lcdtest() == false) {
      Serial.println(F("lcd"));
    }
    else {
      Serial.println(F("microbit"));
    }
  }
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(A0, INPUT);
  pinMode(A2, INPUT);

  digitalWrite(A3, HIGH);
  pinMode(A3, OUTPUT);
  digitalWrite(A3, HIGH);
  lcd.begin(16, 2);
  pinMode(8, OUTPUT);
  pinMode(13, INPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, INPUT);
  Serial.begin(9600);
  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println(F("\n\nAdafruit finger detect test"));

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println(F("Found fingerprint sensor!"));
  } else {
    Serial.println(F("Did not find fingerprint sensor :("));
//    resetr();

  }

  finger.getTemplateCount();
  Serial.print(F("Sensor contains ")); Serial.print(finger.templateCount); Serial.println(F(" templates"));

}

void loop()                     // run over and over again
{

  if (Serial.available()) {

    String word1 = Serial.readString();
    word1.trim();
    String word2 = F("test");
    if (word1 == "257" || authenticated == true) {
      Serial.println(F("correct"));
      delay(100);
      if (!authenticated) {

        Serial.println(F("authenticated"));
      }
      while (Serial.available() == false && !authenticated) {

      }
      if (!authenticated) {
        word1 = Serial.readString();
        word1.trim();

      }
      authenticated = true;
      Serial.println(word1);

      if (word1.equals(word2)) {
        Serial.println(F("testing"));
        if (testcon()) {
          Serial.println(F("functional"));
        }
        else {
          Serial.println(F("error"));
        }
      }
      else {

        if (word1.equals(F("qtest"))) {
          Serial.println(F("quiet testing"));
          Serial.println(qtestcon());
        }
        else {
          if (word1.equals(F("toggle"))) {
            armedup();
            if (armed) {




            }
            else {

            }
            if (qtestcon()) {
              digitalWrite(8, HIGH);
              delay(750);
              digitalWrite(8, LOW);
              delay(1000);
              Serial.println(F("done"));
              lcd.clear();
              lcd.print("toggled");
              armedup();
              Serial.println(armed);

            }
            else {
              Serial.println("error");
            }

          }
          else {
            if (word1.equals(F("toggle testing"))) {
              if (autotest) {
                autotest = false;
                Serial.println(F("testing disabled"));
              }
              else {
                autotest = true;
                Serial.println(F("testing enabled"));
              }
            }
            else {
              if (word1.equals(F("syst check"))) {
                Serial.println(F("starting"));
                lcd.clear();
                lcd.print(F("testing now"));
                delay(1000);
                lcd.clear();
                autotest = false;
                armedup();
                startsysarmed = armed;
                testing = true;
              }
              else {
                if (word1.equals(F("eeprom"))) {
                  Serial.println(EEPROM.read(1));
                }
                else {
                  if (word1.equals(F("ereset"))) {
                    EEPROM.write(1, 0);
                    Serial.println(F("reset"));
                  }

                  else {
                    if (word1.equals(F("disr"))) {
                      Serial.println(F("ok"));
                      lcd.clear();
                      lcd.noDisplay();
                      delay(100);
                      lcd.display();
                    }
                    else {
                      if (word1.equals(F("reset")) || word1.equals(F("r"))) {
                        Serial.println("reseting.....");
                        delay(1000);
                        resetr();
                      }
                      else {
                        Serial.println(F("Unknown word"));
                      }
                    }
                  }
                }
              }
            }
          }
        }

      }
    }


    else {
      Serial.println("wrong code" + word1);

    }
  }
  if (inmenu == false) {

    if (digitalRead(A0) == HIGH && waiting == false) {
      waiting = true;
      int numalarms = EEPROM.read(1);
      EEPROM.write(1, numalarms + 1);
      Serial.println("yes " + numalarms);
      while (digitalRead(A0) == HIGH) {

      }
    }
    else {
      delay(10);
      if (digitalRead(A0) == LOW && waiting == true) {
        waiting = false;
      }

    }



    getFingerprintIDez();
    t.handle();
    lcd.clear();
    lcd.setCursor(0, 1);

    t.setInterval([]() {
      armedup();
      if (!printing) {
        if (armed) {
          Serial.println(F("armed"));
        }
        if (!armed) {
          Serial.println(F("disarmed"));
        }
      }
      counter++;
      com++;
      testcounter++;
      if (authenticated) {
        a++;
      }
      if (testing) {
        systcounter++;

        Serial.println(systcounter);
      }
    }, 1000);
    if (counter >= lastcounter + 10) {
      showa = false;
    }
    if (counter >= 1000) {
      counter = 0;
      lastcounter = 0;
    }
    if (a >= la + 10) {
      if (authenticated) {
        Serial.println("authentication expired");
      }
      authenticated = false;

    }
    if (a >= 10) {
      a = 0;
      la = 0;
    }
    if (systcounter >= lsystcounter + 1000) {
      if (testing) {
        testing = false;
        armedup();
        if (armed == startsysarmed) {
          Serial.println(F("true"));
          lasttest = true;
          testing = false;
          autotest = true;
        }
        else {
          lasttest = false;
          Serial.println(F("false"));
        }
      }
    }
    if (systcounter >= 1000) {
      systcounter = 0;
      lsystcounter = 0;
    }
    if (com >= lcom + testr) {
      if (autotest) {
        testcon();
      }
      lcom = com;
    }
    if (com >= 1000) {
      com = 0;
      lcom = 0;
    }
    if (com >= lcom + testr - 15) {
      if (autotest) {
        if (!printing) {
          Serial.println("test");
          printing = true;
          printc = 100;
        }
        else {
          printc--;
          if (printc == 0) {
            printing = false;
          }
        }

      }

    }
    if (testcounter >= ltestcounter + testdis - 15) {
      if (autotest) {
        if (!printing) {
          Serial.println("test");
          printing = true;
          printc = 100;
        }
        else {
          printc--;
          if (printc == 0) {
            printing = false;
          }
        }

      }

    }
    if (testcounter >= ltestcounter + testdis) {
      if (autotest) {
        shouldtest = true;
      }
      ltestcounter = testcounter;
    }
    if (testcounter >= 1000) {
      testcounter = 0;
      ltestcounter = 0;
    }
    if (showa == true) {
      lcd.setCursor(0, 0);
      lcd.print(F("accepted"));

      lcd.setCursor(0, 1);
    }
    else {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(EEPROM.read(1));
      lcd.setCursor(0, 1);
    }
    armedup();
    if (armed == true) {
      lcd.print(F("armed"));
    }
    else {
      lcd.print(F("disarmed"));
      if (shouldtest == true) {
        shouldtest = false;
      
      if (qtestcon() == true) {
        EEPROM.update(1, 0);
      }
      else {
        testcon();
      }
    }
  }
  }
else {
  lcd.clear();
  if (digitalRead(9) == HIGH) {
    items++;
  }
  if (items > 2) {
    items = 0;
  }
  lcd.print(options[items]);
  delay(10);
  if (digitalRead(10) == HIGH) {
    if (items == 2) {
      inmenu = false;
    }
    if (items == 1) {
      bool ready = false;
      int current = finger.templateCount;
      while (!ready) {
        if (digitalRead(9) == HIGH) {
          current++;
          if (current > finger.templateCount) {
            current = 3;
          }

        }
        if (finger.templateCount != 2) {


          lcd.clear();
          delay(10);
          lcd.print(current);
          delay(500);
          if (digitalRead(10) == HIGH) {
            ready = true;
            inmenu = false;
            Serial.println("removing " + current);
            removef(current);
            lcd.clear();
            lcd.print("done");
          }
        }
        else {
          lcd.clear();
          lcd.print(F("none to remove"));
          delay(1000);
          inmenu = false;
        }
      }
    }
    if (items == 0) {
      enroll(finger.templateCount + 1);
    }
    if (items < 0) {
      items = 2;
    }


  }
}
}

You seem to try to add a function definition inside setup.
That is not allowed.
A function definition looks like

type name(){
}

In your case

void armedup()

If you want to call the function, leave out void.
If you want to define a function, move it up above setup or down below loop.

1 Like

the line added was running a hardware reset function.

and the function definitions are in other files

Remove void then.
And you need to include a .h file where the function prototype is given.

the error is referring to the definition file

and there is an .h

What exactly did you add in setup then?
And is the .h file from a known library or 'homemade'?
Can you paste all your code?
Or just until end of setup?

Post ALL of your code. It is very hard to try and debug code when you don't have all of it.

Ok I’ll do so tomorrow

done

Where are armedup() and qtestcon() functions defined? The compiler can't find them.

other files they work just fine on there own

What is this type of construction?

t.setInterval([]() {

Why are your } not properly lined out?

How can we see what is wrong in updatearmed line 1, position 15 if you do not share that file?

here is update armed

void armedup(){
    if(digitalRead(13)==HIGH){
    armed=true;
    }
    else{
      armed=false;
    }
}

and setinterval is from a time keeping library

it broke after adding line #89 but does not work if it is removed

What kind of file is updatearmed?

I would expect .h or .cpp

Did you #include the file somewhere?
Does it have header guards?
Is there nothing else in that file?
Like one lonely bracket ((, { or [) or so?

Because nothing seems wrong with that function...

That is not in the code you posted. Neither is qtestcon().

Have a look again at post #12...
To me that seems like a strange way to call a function...

It is calling it with the first parameter as a lambda function. See this example: https://github.com/Aasim-A/AsyncTimer/blob/master/examples/BlinkUsingInterval/BlinkUsingInterval.ino

Isn't a lambda function supposed to be small?
Is anything after { until the next } part of this lambda function.
I am not really familiar with this in C++ (have seen it in Python).

It should be small. I prefer to use named callback functions but that is just me. Yes function is { until }