I’m not able to get one of my programs to run when using either the sqrt or pow functions. Here’s the code:
int analogPin = A0;
int analogPowerPin = D2;
float sampleMean = 0;
float sampleDev = 0;
int sample;
float sampleSum = 0;
float sampleArray[10] = {0};
//Functions
int takeSample(String sampleEnable);
void setup() {
Serial.begin(9600);
pinMode(analogPin, INPUT);
pinMode(analogPowerPin, OUTPUT);
Spark.variable("poolLevel", &sampleMean, DOUBLE);
Spark.variable("poolVariance", &sampleDev, DOUBLE);
}
void loop() {
//Spark.publish("Level", "15");
sampleSum = 0;
for (int i = 0; i < 10; ++i) {
sample = analogRead(A0);
Serial.print(i);
Serial.print(": ");
Serial.println(sample);
sampleArray[i] = sample;
sampleSum += sample;
delay(1000);
}
sampleMean = (sampleSum/10);
Serial.println();
Serial.print("Mean: ");
Serial.println(sampleMean);
sampleDev = 0;
for (int i = 0; i <10; ++i) {
sampleDev += (sampleMean - sampleArray[i]) * (sampleMean - sampleArray[i]);
}
sampleDev = sqrt(sampleDev/10); // problem line, will compile if I comment this out
Serial.println();
Serial.print("Sample Var: ");
Serial.println(sampleDev);
delay(5000);
}
and here's the error message:
isy_cloud_connector.cpp: In function 'void loop()':
isy_cloud_connector.cpp:46:30: error: 'sqrt' was not declared in this scope
Serial.println(sampleMean);
^
make: *** [isy_cloud_connector.o] Error 1
When I comment out the line using the sqrt function the program will compile just fine. Interestingly, I’m getting a ton of what appear to be unrelated compiler errors before the one I’ve listed above.
Thanks for any help!
Scott