error: 'delayMicroseconds' was not declared in this scope

Hi,

I have two files in my sketch folder: sketch.ino and sub.c

My .ino file looks like this:

#include "sub.c"
void setup(){
  doSetup();
}
void loop() { }

My sub.c file looks like this:

#include "util/delay.h"
void doSetup();
void doSetup() {
  delayMicroseconds(1000);
}

But when I compile I get the following error:

lcd.c:48: error: 'delayMicroseconds' was not declared in this scope

What am I doing wrong?

Try to add
#include "Arduino.h"
into your sub.c

Worked like a charm, thank you!

Pito's answer works, but more importantly, do you understand why it works? Also, the #include directive was never intended to be used with source code files (e.g., .c). Instead, #include preprocessor directives should be used with header files (.h).

Rename sub.c to sub.cpp, remove the #include of sub.c from sketch.ino, restart the IDE and try again.

Pete