I am processing some strings received over serial input, and need to test if they are numeric.
"isNumeric" is a common function built into almost all programming languages I have used including SAP ABAP, VB, VBA, TSQL , Crystal reports and others.
I found this "isNumeric" function on the internet for arduino, it works on arduino boards but fails on the teensy at the "isdigit" function . Can anyone suggest an "isNumeric" function for Teensy?
// check a string to see if it is numeric
bool isNumeric(String str){
for(byte i=0;i<str.length();i++)
{
if(isDigit(str.charAt(i))) return true;
}
return false;
}
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(13, OUTPUT);
}
bool isNumeric(String str){
for(byte i=0;i<str.length();i++)
{
if(isDigit(str.charAt(i))) return true;
}
return false;
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(13, LOW);
if (isNumeric("aaaa") ) digitalWrite(13, HIGH);
if (isNumeric("12345")) digitalWrite(13, HIGH);
}
"isNumeric" is a common function built into almost all programming languages I have used including SAP ABAP, VB, VBA, TSQL , Crystal reports and others.
I found this "isNumeric" function on the internet for arduino, it works on arduino boards but fails on the teensy at the "isdigit" function . Can anyone suggest an "isNumeric" function for Teensy?
// check a string to see if it is numeric
bool isNumeric(String str){
for(byte i=0;i<str.length();i++)
{
if(isDigit(str.charAt(i))) return true;
}
return false;
}
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(13, OUTPUT);
}
bool isNumeric(String str){
for(byte i=0;i<str.length();i++)
{
if(isDigit(str.charAt(i))) return true;
}
return false;
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(13, LOW);
if (isNumeric("aaaa") ) digitalWrite(13, HIGH);
if (isNumeric("12345")) digitalWrite(13, HIGH);
}