@lightx, it is behaving as if `#include “application.h” is not there but if your file is a .ino file then the compiler takes care of adding that. Can you paste your code here so I can take a look?
#include "elapsedMillis.h"
elapsedMillis timeElapsed; //declare global if you don't want it reset every time loop runs
// Debug mode
boolean DEBUG = false;
// motion variables BEGIN -----------------------------------
int val = 0;
int calibrateTime = 10000; // wait for the thingy to calibrate
long unsigned int lowIn; // the time when the sensor outputs a low impulse
unsigned long pause = 60000UL; // amount of milliseconds the sensor has to be low before we assume all motion has stopped
boolean lockLow = true;
boolean takeLowTime;
boolean currentMotion = false;
int pirPin = D0; //the digital pin connected to the PIR sensor's output
// motion variables END -------------------------------------
int ledPin = D1; // led pin
char myIpString[24]; // localIP
// light sensor pin
int ldrPin = A0; //analog pin 0
unsigned int ldrReading = 0;
// delay in milliseconds
unsigned int interval = 1000;
void setup() {
Serial.begin(9600);
if(DEBUG){Serial.println("Registering Variables");}
// my network localIP
IPAddress localIp = WiFi.localIP();
sprintf(myIpString, "%d.%d.%d.%d", localIp[0], localIp[1], localIp[2], localIp[3]);
Spark.variable("ipAddress", myIpString, STRING);
Spark.variable("motion", ¤tMotion, BOOLEAN);
Spark.publish("boulder rev 14 is online...", NULL, 60, PRIVATE);
Spark.variable("ldrReading", &ldrReading, INT);
pinMode(ledPin, OUTPUT); // led as output
pinMode(pirPin, INPUT); // declare sensor as input
pinMode(ldrPin, INPUT);
if(DEBUG){Serial.println(".. done");}
// take control of the LED
RGB.control(true);
// red, green, blue, 0-255
RGB.color(0, 0, 0);
delay(20);
}
void loop() {
if (calibrated()) { ////
readTheSensor(); // motion
reportTheData(); ////
}
ldrReading = analogRead(ldrPin);
publishLDR();
}
void publishLDR() {
if (timeElapsed > interval) {
Spark.publish("ldrReading", NULL, 60, PRIVATE);
}
timeElapsed = 0;
}
bool calibrated() {
return millis() - calibrateTime > 0;
}
void readTheSensor() {
val = digitalRead(pirPin);
}
void reportTheData() {
if(digitalRead(pirPin) == HIGH){
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
digitalWrite(ledPin, HIGH);
if(DEBUG) {
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
}
delay(50);
currentMotion = true;
Spark.publish("boulder_motion", "true");
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
if(takeLowTime) {
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause) {
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
digitalWrite(ledPin, LOW);
Spark.publish("boulder motion ended", NULL, 60, PRIVATE);
if(DEBUG) {
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
}
delay(50);
currentMotion = false;
Spark.publish("boulder_motion", "false");
}
}
}
indeed @peekay123 and since the error was the .H tab. The problem was the millis function which it shoudnt do that .. right?! why a function like millis() giving an error I guess is my point.
I had this problem last week and for me it was due to having an #include statement on the first line. I had removed the comment about the IDE adding that include to clean up my code. Adding an empty line or comment on line 1 fixed this issue. Also mentioned here: #Include on first line fails to compile in Sparkulator
thank you @peekay123, @mdma and @ScruffR for pointing me to “application.h” (yes I should have listen to @peekay123 in the first place)
one quick question, why isnt there something about “application.h” in docs.particle.io? Im hacking my way through this and I would love to know more about what this “application.h” is.
application.h is just a header file that wraps up a bunch of other #include statements so that you can use all the classes and functions you’d usually need for writing your program (e.g. spark_wiring.h) - this is similar to Arduino.h on that platform.
With this one header you’ll have some abstraction layer (e.g. spark_wiring.h can be changed to particle_wiring.h behind the scenes without breaking existing code) and you got the convenience that you only need to add one header instead of a bunch.
Another background info:
If your main project file is an .INO file, you don’t need to #include "application.h" since the preprocessor will do that for you. In a .H/.CPP file, you need to do it yourself.