Why do I get this "function not declared in this scope" error?

Hello everyone, I'm still kinda new to Arduino, but I thought that I at least knew the basics to work with it for a school project of mine, however, when trying t compile my project, I just got this Error and I really don't know why:
5 Replies
¬NichtBen
¬NichtBenOP5d ago
SSSurfer\SSSurfer.ino: In function 'void loop()':
SSSurfer\SSSurfer.ino:18:3: error: 'delayCheck' was not declared in this scope
delayCheck(5000, 1000, 505, 328);
^~~~~~~~~~
SSSurfer\SSSurfer.ino:18:3: note: suggested alternative: 'delay'
delayCheck(5000, 1000, 505, 328);
^~~~~~~~~~
delay
SSSurfer\SSSurfer.ino:20:7: error: 'inRange' was not declared in this scope
if (inRange(analogRead(buttonPin), 505)) {
^~~~~~~
exit status 1

Compilation error: 'delayCheck' was not declared in this scope
SSSurfer\SSSurfer.ino: In function 'void loop()':
SSSurfer\SSSurfer.ino:18:3: error: 'delayCheck' was not declared in this scope
delayCheck(5000, 1000, 505, 328);
^~~~~~~~~~
SSSurfer\SSSurfer.ino:18:3: note: suggested alternative: 'delay'
delayCheck(5000, 1000, 505, 328);
^~~~~~~~~~
delay
SSSurfer\SSSurfer.ino:20:7: error: 'inRange' was not declared in this scope
if (inRange(analogRead(buttonPin), 505)) {
^~~~~~~
exit status 1

Compilation error: 'delayCheck' was not declared in this scope
I've got two relevant tabs within my project, and I find it strange that it complains about delayCheck and inRange, but not about IdleAnimation for example, despite being declared in the same tab: SSSurfer.ino:
#include <LedControl.h>
const int buttonPin = A5;

LedControl lc = LedControl(12, 11, 10, 1); //DIN, CLK, CS, # of Displays connected

void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));

lc.shutdown(0, false);
lc.setIntensity(0, 1); // brightness 0–15
lc.clearDisplay(0);
}

void loop() {
idleAnimation();
delayCheck(5000, 1000, 505, 328);

if (inRange(analogRead(buttonPin), 505)) {
lc.clearDisplay(0);
delay(3000);
ssGame();
}
else if (inRange(analogRead(buttonPin), 328)) {
lc.clearDisplay(0);
delay(3000);
subwayGame();
}
}
#include <LedControl.h>
const int buttonPin = A5;

LedControl lc = LedControl(12, 11, 10, 1); //DIN, CLK, CS, # of Displays connected

void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));

lc.shutdown(0, false);
lc.setIntensity(0, 1); // brightness 0–15
lc.clearDisplay(0);
}

void loop() {
idleAnimation();
delayCheck(5000, 1000, 505, 328);

if (inRange(analogRead(buttonPin), 505)) {
lc.clearDisplay(0);
delay(3000);
ssGame();
}
else if (inRange(analogRead(buttonPin), 328)) {
lc.clearDisplay(0);
delay(3000);
subwayGame();
}
}
funktionen.ino:
void idleAnimation() {
int i = random(1, 4);

if (i == 1) {
idleTalking();
}
if (i == 2) {
idleLooking();
}
if (i == 3) {
idleTurning();
}
}

bool inRange(int input, int target, int range = 10) {
return (input > target - range && input < target + range);
}

void delayCheck(int time, int checkAmount, int buttonA, int buttonB = -1, int buttonC = -1, int buttonD = -1, int buttonE = -1) {
for (int i = 0; i < checkAmount; i++) {
delay(time / checkAmount);

int readValue = analogRead(buttonPin);

if (inRange(readValue, buttonA)) return;

if (readValue != -1 && inRange(readValue, buttonB)) return;
if (readValue != -1 && inRange(readValue, buttonC)) return;
if (readValue != -1 && inRange(readValue, buttonD)) return;
if (readValue != -1 && inRange(readValue, buttonE)) return;
}
}
void idleAnimation() {
int i = random(1, 4);

if (i == 1) {
idleTalking();
}
if (i == 2) {
idleLooking();
}
if (i == 3) {
idleTurning();
}
}

bool inRange(int input, int target, int range = 10) {
return (input > target - range && input < target + range);
}

void delayCheck(int time, int checkAmount, int buttonA, int buttonB = -1, int buttonC = -1, int buttonD = -1, int buttonE = -1) {
for (int i = 0; i < checkAmount; i++) {
delay(time / checkAmount);

int readValue = analogRead(buttonPin);

if (inRange(readValue, buttonA)) return;

if (readValue != -1 && inRange(readValue, buttonB)) return;
if (readValue != -1 && inRange(readValue, buttonC)) return;
if (readValue != -1 && inRange(readValue, buttonD)) return;
if (readValue != -1 && inRange(readValue, buttonE)) return;
}
}
AnonEngineering
Put your functions into a functions.h (not an ino) file, then #include that file in the main sketch. Then it compiles (until it complains about functions you don't have listed above 🙂 )
¬NichtBen
¬NichtBenOP5d ago
I assume it's not as easy as to just change the file extension from .ino to .h, right? Also how come that this issue is only popping up now, I have a bunch of different tabs in my project, and this is the first time that I got this. I used different functions across mutiple tabs a bunch of times now.
AnonEngineering
should be able to simply rename the tab
jim lee
jim lee3d ago
There's no #include for it anyway.

Did you find this page helpful?