real noob here trying to figure out a sketch
can someone explain "if (isnan (c))"
Thanks
real noob here trying to figure out a sketch
can someone explain "if (isnan (c))"
Thanks
Hard without any other context but isnan looks like a function that takes in a variable c and returns a Boolean variable.
Is Not A Number
is how I would interpret it.
Some floating point values are not valid, so are described as NaN
Of course, more context would make things clearer.
googling for arduino isnan brought me here:
Absolute noob here - I am having difficulty getting a LCD to operate with a thermocouple. A sketch for the serial works fine but with the LCD I get the message after the "if" condition. If I knew what that was, I might be able to figure out why the LCD is not working properly - seems to be hooked up to the UNO okay since "Hello, world!" works fine
The "if" condition is about 12 lines from the bottom.
The thermocouple is connected to a MAX TC amp from Adafruit. It all works fine with the serial monitor.
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>
int thermoCLK = 3;
int thermoCS = 4;
int thermoDO = 5;
// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(11,12,7,8,9,10);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("MAX31855 test");
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
// basic readout test, just print the current temp
lcd.setCursor(0, 0);
lcd.print("Int. Temp = ");
lcd.print(thermocouple.readInternal());
lcd.print(" ");
double c = thermocouple.readCelsius();
lcd.setCursor(0, 1);
if (isnan(c))
{
lcd.print("T/C Problem");
}
else
{
lcd.print("C = ");
lcd.print(c);
lcd.print(" ");
}
delay(1000);
}
I'd probably print the value of "c" in hex, cast to an "unsigned long".
if (isnan(c))
{
Serial.print((unsigned long) c, HEX);
}
Regarding isnan(): std::isnan - cppreference.com
Does the liquidCrystal support printing floats? The reference page suggests it does not:
AWOL:
I'd probably print the value of "c" in hex, cast to an "unsigned long".if (isnan(c))
{
Serial.print((unsigned long) c, HEX);
}
If c is not a number, is it really a good idea to print a number? Why not:
if (isnan(c))
{
Serial.print("NaN");
}
although the Print class already does this check.
If c is not a number, is it really a good idea to print a number? W
I'm just curious to see which particular NaN pattern has been chosen.
I did say it was a personal thing.