Trouble with data types...I think?

Dear learned and wise of t'interweb,

Over the last few weeks I have been trying to develop a system to measure the mains current being drawn in a house, using a current transformer as an input. I have learned a lot on the way, but still consider myself a newbie. Just yesterday I discovered that some kind soul has written a library function that will do just what I want, and (damn it!) a lot better than my old sketch...though not quite, and it is the not quite part for which I crave your sympathy and assistance.

The question is quite simple, and I hope the answer is too.
This new sketch (see below) returns a variable 'Irms', and I believe that (please correct me if wrong) Irms is data type 'double'. Is there a simple way for a newbie to read the data type of a returned variable? I want to compare Irms with a second variable, and do something if Irms > secondVariable. I suppose this means that Irms and secondVariable must be the same data type. Is this so (simplified answers, please!)?

I have been guilty of failing to post code, posting snippets, and failing to provide schematics in the past. Though I feel they are verbose in this case, they are included below so that I don't transgress this time!

The link to the tutorial/project is How to Build an Arduino Energy Monitor - Measuring Mains Current Only — OpenEnergyMonitor 0.0.1 documentation

The code is

#include "EmonLib.h"
// Include Emon Library
EnergyMonitor emon1;
// Create an instance
void setup()
{
  Serial.begin(9600);

  emon1.current(1, 111.1);             // Current: input pin, calibration.
}

void loop()
{
double Irms = emon1.calcIrms(1480);  // Calculate Irms only
Serial.print(Irms*230.0);           // Apparent power
  Serial.print(" ");
  Serial.println(Irms);             // Irms
}

My (pseudo-code) addition to the code above will be something like:

If Irms > secondVariable
{
digital.write (pin13, HIGH);
}
else digital.write (pin13, LOW);

but (admittedly late!) last night I couldn't get my comparator to change the state of Pin13, though it had (within another sketch) produced the expected outcomes when comparing two integer variables, and by this I mean that despite there being numerous syntax errors in my pseudo-code above, I have grasped the basics of comparing two integers previously...it's the possible complications of trying to compare a 'double' (or whatever datatype Irms is) with another value that have me confused.
Perhaps you can point me to a tutorial on that very subject?

Your guidance gratefully received,

GM

I just looked again at the Arduino Reference pages, and it seems that I overlooked the 'conversion of data type to ...'

So, just thinking out loud here, if I wanted to compare a value (returned from a function) of 3.142 with an integer value but not lose precision then presumably I could do the following:

int triggerPoint = 4000 //above this value I want to energise a relay
Irms = 3.142;            //as returned from an analog reading and filtering function.
int Irms = Irms*1000; //now it's 3142 and should convert exactly into an integer value

If (Irms > triggerPoint)
{
digital.write (pin13, LOW);
}
else digital.write (pin13, HIGH);

So am I right to self-conclude that I don't need to know the returned data type (for my newbie application), I leave the software to convert whatever type it is into an integer, then compare the converted value with my integer trigger value?

Did you set pin 13 to pinMode(OUTPUT) in setup()? The digitalWrite will not work on a pin that is not set to OUTPUT.

groundFungus:
Did you set pin 13 to pinMode(OUTPUT) in setup()? The digitalWrite will not work on a pin that is not set to OUTPUT.

Well it will work, for a particular definition of "work" :wink:

Glorymill:
Is there a simple way for a newbie to read the data type of a returned variable?

https://www.google.com/search?q=avr+gcc+data+types
https://www.google.com/search?q=avr+gcc+double

I want to compare Irms with a second variable, and do something if Irms > secondVariable. I suppose this means that Irms and secondVariable must be the same data type.

Not "must" but making them the same datatype avoids some potential pitfalls.

And, comparing floating-point values for equality often ends in tears.

Thanks again for all your help and advice, and for the links to further learning. I will implement your recommendations on the next opportunity I get to play with my wee project.

There seems little point to me in using another's code inside my project if I can't at least understand, follow, and learn from it, but having tried the Emonlib.h library and compared the results to those from my own code I concede that it is much much better. I shall comsole myself with the fact that I have learnt some new code along the way, and will learn more as I dissect emonlib.h further. Once I learn that I can learn to ask the right questions!

On the subject of 'googling', there definitely is a whole world of experience out there, but as a newbie it is very easy to get bogged-down in jargon and higher functions that are beyond my capabilities at the moment, The particular skills you guys possess is that you seem to have a second sense for the level at which your 'tutees' can absorb information, and you give just about the right level of complexity in your answers; I'm grateful for that, unfortunately that's the same reason why I keep coming back with my dumb questions!!!

Over and out (for now), GM