A function-definition is not allowed here before '{' token when as a Tab

Hi,
This sketch was compiling well.
Error came when works as a Tab and modified just a little as noted. why?

a function-definition is not allowed here before '{' token

ERROR:

Arduino: 1.8.13 (Windows 7), Board: "Arduino Uno"





















C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10813 -build-path C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_build_905466 -warnings=none -build-cache C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_cache_981239 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose E:\ENGINEERING\DIY\Electronic\meter\Arduino Multimeter\00_MAIN\MEGA2560.MAIN_test\MEGA2560.MAIN_test.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10813 -build-path C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_build_905466 -warnings=none -build-cache C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_cache_981239 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose E:\ENGINEERING\DIY\Electronic\meter\Arduino Multimeter\00_MAIN\MEGA2560.MAIN_test\MEGA2560.MAIN_test.ino

Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Detecting libraries used...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Alternatives for LiquidCrystal.h: [LiquidCrystal-1.0.7@1.0.7]

ResolveLibrary(LiquidCrystal.h)

  -> candidates: [LiquidCrystal-1.0.7@1.0.7]

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src\\LiquidCrystal.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Generating function prototypes...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\preproc\\ctags_target_for_gcc_minus_e.cpp" -DARDUINO_LIB_DISCOVERY_PHASE

"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp.o"

E:\ENGINEERING\DIY\Electronic\meter\Arduino Multimeter\00_MAIN\MEGA2560.MAIN_test\MEGA2560.MAIN_test.ino: In function 'void setup()':

MEGA2560.MAIN_test:72:13: error: a function-definition is not allowed here before '{' token

 void loop() {

             ^

ACDC:32:1: error: a function-definition is not allowed here before '{' token

 {

 ^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:30:0,

                 from C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_build_905466\sketch\MEGA2560.MAIN_test.ino.cpp:1:

ACDC:55:1: error: expected unqualified-id before string constant

 ISR (ANALOG_COMP_vect)

 ^

ACDC:56:1: error: a function-definition is not allowed here before '{' token

 {

 ^

ACDC:69:1: error: a function-definition is not allowed here before '{' token

 {

 ^

ACDC:164:28: error: a function-definition is not allowed here before '{' token

 void ACDCch_select(byte n) {  // added "ACDC"

                            ^

ACDC:191:1: error: expected '}' at end of input

 }

 ^

Using library LiquidCrystal-1.0.7 at version 1.0.7 in folder: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\LiquidCrystal-1.0.7 

exit status 1

a function-definition is not allowed here before '{' token


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.

1 Like

Thanks.
Changed a little:

/**************************************************************************

   Arduino autoranging AC/DC voltmeter.
   Voltage and frequency are printed on 1602 LCD screen.
   This is a free software with NO WARRANTY - Use it at your own risk!
   https://simple-circuit.com/


 *************************************************************************/

void ACDC(void)
{
#include <LiquidCrystal.h>   // include Arduino LCD library
  // LCD module connections (RS, E, D4, D5, D6, D7)
  LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

  // define autoranging channel pins
#define CH0  2
#define CH1  3
#define CH2  4
#define CH3  5

  const uint16_t Time_Out = 50000,  // time out in microseconds
                 Periods  = 10;     // number of periods of measurement (for AC voltage only)

  // variables
  byte ch_number;
  const uint16_t res_table[4] = {2444, 244, 94, 47},  // voltage divider resistances in tenths kOhms
                                total_res = 22444;                   // total resistance in tenths kOhms
  uint16_t current_res;
  volatile byte per;

  void setup(void)
  {
    pinMode(CH0, OUTPUT);
    pinMode(CH1, OUTPUT);
    pinMode(CH2, OUTPUT);
    pinMode(CH3, OUTPUT);

    lcd.begin(16, 2);     // set up the LCD's number of columns and rows
    lcd.setCursor(1, 0);
    lcd.print("Voltage:");
    //// lcd.print("Hello!");

    ch_number = 0;
    ch_select(ch_number);

    // ADC and analog comparator configuration
    ADMUX  = 0x03;
    ADCSRA = 0x87;
    ADCSRB = (0 << ACME);  // select AIN1 as comparator negative input
    ACSR   = 0x13;         // turn on analog comparator

  }

  // analog comparator ISR
  ISR (ANALOG_COMP_vect)
  {
    byte count = 0;
    for (byte i = 0; i < 50; i++) {
      if ( ACSR & 0x20 )
        count++;
    }

    if (count > 48)
      per++;
  }

  // main loop
  void loop()  
  {
    bool dc_flag = 0; // DC voltage flag bit
    int32_t sum = 0;  // sum of all readings
    uint16_t n = 0;   // number of readings (samples)

    ACSR = (1 << ACI);   // clear analog comparator interrupt flag
    ACSR = (1 << ACIE);  // enable analog comparator interrupt

    uint32_t current_m = micros();  // save current millis
    byte current_per = per;         // save current period number
    while ( (current_per == per) && (micros() - current_m < Time_Out) ) ;

    if ( micros() - current_m >= Time_Out ) { // if there's time out event ==> voltage signal is DC
      dc_flag = 1;
      for (byte i = 0; i < 200; i++) {
        ADCSRA |= 1 << ADSC;   // start conversion
        while (ADCSRA & 0x40); // wait for conversion complete
        int16_t an = (int16_t)(ADCL | (uint16_t)ADCH << 8) - 511;
        sum += an;
        n++;         // increment number of readings
        delay(1);
      }
    }

    else {   // here, voltage signal is AC
      current_m = micros();  // save current millis()
      per = 0;
      while ( (per < Periods) && (micros() - current_m < (uint32_t)Time_Out * Periods) ) {
        ADCSRA |= 1 << ADSC;   // start conversion
        while (ADCSRA & 0x40); // wait for conversion complete
        int32_t an = (int16_t)(ADCL | (uint16_t)ADCH << 8) - 511;
        sum += sq(an);  // sq: square
        n++;            // increment number of readings
      }
    }

    ACSR = (0 << ACIE);  // disable analog comparator interrupt
    uint32_t total_time = micros() - current_m;  // used to claculate frequency

    // voltage calculation
    float v;
    if (dc_flag)  // if voltage signal is DC
      v = (4 * sum) / n; // calculate Arduino analog channel DC voltage in milli-Volts

    else  // here voltage signal is AC
      v = 4 * sqrt(sum / n); // calculate Arduino analog channel RMS voltage in milli-Volts

    // claculate actual (input) voltage in milli-Volts (apply voltage divider equation)
    v = v * (float)total_res / current_res;
    v /= 1000;  // get voltage in Volts

    uint16_t v_abs = abs(int16_t(v));
    if ( (v_abs >= 10 && ch_number == 0) || (v_abs >= 100 && ch_number == 1) || (v_abs >= 250 && ch_number == 2) ) {
      ch_number++;
      ch_select(ch_number);
      delay(10);
      return;
    }

    if ( (v_abs < 220 && ch_number == 3) || (v_abs < 80 && ch_number == 2) || (v_abs < 8 && ch_number == 1) ) {
      ch_number--;
      ch_select(ch_number);
      delay(10);
      return;
    }

    char _buffer[8];
    lcd.setCursor(0, 1);
    if ( v < 0)
      lcd.print('-');
    else
      lcd.print(' ');
    if (v_abs < 10)
      sprintf( _buffer, "%01u.%02u", v_abs, abs((int16_t)(v * 100)) % 100 );
    else if ( v_abs < 100)
      sprintf( _buffer, "%02u.%01u", v_abs, abs((int16_t)(v * 10)) % 10 );
    else
      sprintf( _buffer, "%03u ", v_abs );

    lcd.print(_buffer);
    if (dc_flag)
      lcd.print("VDC        ");
    else {
      lcd.print("VAC ");
      // calculate signal frequency in Hz
      uint32_t period_time = total_time / Periods;
      float freq = 1000000.0 / period_time;
      sprintf( _buffer, "%02u.%02uHz", (uint16_t)freq % 100, (uint16_t)(freq * 100) % 100 );
      lcd.print(_buffer);
    }

    delay(500);    // wait half a second

  }

  void ch_select(byte n) {  // added "ACDC"
    switch (n) {
      case 0:
        digitalWrite(CH0, HIGH);
        digitalWrite(CH1, LOW);
        digitalWrite(CH2, LOW);
        digitalWrite(CH3, LOW);
        break;
      case 1:
        digitalWrite(CH0, LOW);
        digitalWrite(CH1, HIGH);
        digitalWrite(CH2, LOW);
        digitalWrite(CH3, LOW);
        break;
      case 2:
        digitalWrite(CH0, LOW);
        digitalWrite(CH1, LOW);
        digitalWrite(CH2, HIGH);
        digitalWrite(CH3, LOW);
        break;
      case 3:
        digitalWrite(CH0, LOW);
        digitalWrite(CH1, LOW);
        digitalWrite(CH2, LOW);
        digitalWrite(CH3, HIGH);
    }
    current_res = res_table[n];
  }
}

ERROR:

Arduino: 1.8.13 (Windows 7), Board: "Arduino Uno"





















C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10813 -build-path C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_build_905466 -warnings=none -build-cache C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_cache_981239 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose E:\ENGINEERING\DIY\Electronic\meter\Arduino Multimeter\00_MAIN\MEGA2560.MAIN_test\MEGA2560.MAIN_test.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\HUA.DELLV-PC\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10813 -build-path C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_build_905466 -warnings=none -build-cache C:\Users\HUA~1.DEL\AppData\Local\Temp\arduino_cache_981239 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose E:\ENGINEERING\DIY\Electronic\meter\Arduino Multimeter\00_MAIN\MEGA2560.MAIN_test\MEGA2560.MAIN_test.ino

Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Detecting libraries used...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Alternatives for LiquidCrystal.h: [LiquidCrystal-1.0.7@1.0.7]

ResolveLibrary(LiquidCrystal.h)

  -> candidates: [LiquidCrystal-1.0.7@1.0.7]

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src\\LiquidCrystal.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Generating function prototypes...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\preproc\\ctags_target_for_gcc_minus_e.cpp" -DARDUINO_LIB_DISCOVERY_PHASE

"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\HUA.DELLV-PC\\Documents\\Arduino\\libraries\\LiquidCrystal-1.0.7\\src" "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp" -o "C:\\Users\\HUA~1.DEL\\AppData\\Local\\Temp\\arduino_build_905466\\sketch\\MEGA2560.MAIN_test.ino.cpp.o"

E:\ENGINEERING\DIY\Electronic\meter\Arduino Multimeter\00_MAIN\MEGA2560.MAIN_test\MEGA2560.MAIN_test.ino: In function 'void setup()':

MEGA2560.MAIN_test:72:13: error: a function-definition is not allowed here before '{' token

 void loop() {

             ^

ACDC:12:1: error: a function-definition is not allowed here before '{' token

 {

 ^

ACDC:194:1: error: expected '}' at end of input

 }

 ^

Using library LiquidCrystal-1.0.7 at version 1.0.7 in folder: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\LiquidCrystal-1.0.7 

exit status 1

a function-definition is not allowed here before '{' token


void ACDC(void)
{

???????????????????????????????????

You have a problem with the above function definition.

1 Like

Thanks.
The sketch work as a Tab of another sketch which call it:

void loop() {
  
  void ACDC(void);
  void PWMGen(void);
}

Is this OK, or how can call it?

Those lines are function prototypes, the compiler should do these for you.


To call a function:
void ACDC(void); <-------<<<< NO, this is a function prototype

ACDC(some variable or value); <-------<<<< YES

1 Like

Thank you.
Can I put any thing there like:

void loop() {
  
  void ACDC(abc);
  void PWMGen(def);
}

Or just nothing:

void loop() {
  
  void ACDC();
  void PWMGen();
}
void loop() {
  
  ACDC(abc);
  PWMGen(def);
}

Or just nothing:

void loop() {
  
  ACDC();
  PWMGen();
}

That is "illegal code". What you probably mean is:

void loop() {
  ACDC();
  PWMGen();
}

The parameters are the things inside the round brackets (). Look at the actual function ACDC to know what and if you need parameters there.

1 Like

Thanks.
There are too many changes happened, its hard to find the info. when I posted this.

In the beginning it is all as clear as mud. Then slowly the waters clear. Go slowly, you'll get there. Maybe try some simpler programs initially...

1 Like

Thanks.
I will.

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