Error 'xxxx' not declared in scope

Hi,
I have been struggling for days as I keep getting errors ‘xxxx’ not declared in this scope
I have copied a function from another file which compiles fine but when brought into my new code, I get errors

any guidance is appreciated
thanks!

@Dup,

show us some code so we can know what’s the issue?

Maybe it’s `#include “application.h” but we need to see just to be sure

@kennethlimcp thanks!

I get this:

In file included from …/inc/spark_wiring.h:30:0,
from …/inc/application.h:31,
from LSM303.cpp:4:
…/…/core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning “Defaulting to Release Build” [-Wcpp]
LSM303.cpp: In function ‘void setup()’:
LSM303.cpp:31:18: error: ‘ledStatus’ was not declared in this scope
LSM303.cpp: In function ‘void loop()’:
LSM303.cpp:92:28: error: ‘xivelycount’ was not declared in this scope
LSM303.cpp: In function ‘void xivelycount(int)’:
LSM303.cpp:130:25: error: ‘ledStatus’ was not declared in this scope
LSM303.cpp:136:26: error: ‘ledStatus’ was not declared in this scope
make: *** [LSM303.o] Error

#include “application.h”
#include “LSM303.h”

LSM303 compass;
TCPClient client;

bool error;
int ledPin = D7;
int doorstate = 0;
int laststate = 0;
int doorcount = 0;
int trigger = 0;
unsigned long LastUpTime = 0;
int x;

// This routine runs only once upon reset
void setup()
{
//Register our Spark function here
// Wire.begin();
error = compass.init(); // Returns “true” if device found
compass.enableDefault();
compass.writeReg(LSM303::CTRL5, 0xE4); //to enable temperature sensor
compass.writeReg(LSM303::CTRL2, 0x00); //to use 2g Acc scale
pinMode(ledPin, OUTPUT);
ledStatus(2, 100); //blink
Serial.begin(9600);
}

void loop()
{
//read the value of mag x
int mx;
mx = compass.m.x;
x = 2000;

	if (mx > x) {
		trigger = HIGH;
		digitalWrite(ledPin, HIGH); //LED turns "on" when magnet is near
	}
	if (mx <= x) {
		trigger = LOW;
		digitalWrite(ledPin, LOW); //LED turns "off" when magnet is mot near
	}

// read the door input pin:
doorstate = trigger;

// compare the doorstate to its previous state
if (doorstate != laststate) {
// if the state has changed, increment the counter
if (doorstate == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
doorcount++;
Serial.println(“on”);
Serial.print("number of door counts: ");
Serial.println(doorcount);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println(“off”);
}
}
// save the current state as the last state,
//for next time through the loop
laststate = doorstate;

// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (doorcount % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

int temp_calc = doorcount;

if (millis()-LastUpTime>4000)
{
xivelycount(temp_calc);
LastUpTime = millis();
}

}

void xivelycount(int count) {

//Serial.println(“Connecting to server…”);
if (client.connect(“api.xively.com”, 8081))
{

    // Connection succesful, update datastreams
    client.print("{");
    client.print("  \"method\" : \"put\",");
    client.print("  \"resource\" : \"/feeds/");
    client.print(FEED_ID);
    client.print("\",");
    client.print("  \"params\" : {},");
    client.print("  \"headers\" : {\"X-ApiKey\":\"");
    client.print(XIVELY_API_KEY);
    client.print("\"},");
    client.print("  \"body\" :");
    client.print("    {");
    client.print("      \"version\" : \"1.0.0\",");
    client.print("      \"datastreams\" : [");
    client.print("        {");
    client.print("          \"id\" : \"countingsheep\",");
    client.print("          \"current_value\" : \"");
    client.print(count);
    client.print("\"");
    client.print("        }");
    client.print("      ]");
    client.print("    },");
    client.print("  \"token\" : \"0x123abc\"");
    client.print("}");
    client.println();

    ledStatus(3, 500);        
} 
else 
{
    // Connection failed
    //Serial.println("connection failed");
    ledStatus(3, 2000);// tried 1000 instead on 2000 to keep the core alive
}


if (client.available()) 
{
    // Read response
    //char c = client.read();
    //Serial.print(c);
}

if (!client.connected()) 
{
    //Serial.println();
    //Serial.println("disconnecting.");
    client.stop();
}

client.flush();
client.stop();

}

void ledStatus(int x, int t)
{
for (int j = 0; j <= x-1; j++)
{
digitalWrite(ledPin, HIGH);
delay(t);
digitalWrite(ledPin, LOW);
delay(t);
}
}

@Dup you can put a prototype of the function ledStatus() before setup() to tell the compiler what it is and how it has to be called once he sees this “suspicious word ledStatus” coming up.
This is pretty much like a variable has to be declared before you can use it.
After all these words don’t mean anything to the compiler unless someone told him what they are supposed to be.

void ledStatus(int x, int t);

void setup()
{
....
}

The same is true for xivelycount.

2 Likes

@ScruffR
thanks!
i should have asked 3 days ago!
no errors!!

thanks!

2 Likes

My pleasure! :wink: Anytime again.

2 Likes