void adcWorker() {
volts = analogRead(voltSense);
float voltage = (volts) * (5.0 / 1023.0); //FIXME: Scale properly to suit 1.25 - 6v input
Serial.print("voltage: ");
Serial.println(voltage);
dtostrf(voltage, 10, 3, strBuf);
size_t n = sizeof(strBuf) / sizeof(strBuf[0]);
// for (size_t i = 0; i < n; i++) {
// Serial.println(strBuf[i]);
// }
for (size_t i = 0; i < n; i++)
{
if ( (strBuf[i] >= '0' && strBuf[i] <= '9') || strBuf[i] == '.')
{
Serial.print(strBuf[i]);
Serial.print(" is in location: ");
Serial.print(i);
Serial.println("");
int j = atoi(strBuf[i]);
Serial.print(strBuf[i]);
Serial.print(" to integer is: ");
Serial.print(j);
Serial.println("");
}
}
//val = atoi((char *)strBuf);
}
the output is:
[codevoltage: 0.71
0 is in location: 5
0 to integer is: 0
. is in location: 6
. to integer is: 0
7 is in location: 7
7 to integer is: 0
1 is in location: 8
1 to integer is: 0
4 is in location: 9
4 to integer is: 0
][/code]
when trying to convert the chars to ints, all that I get is zeros
What you are doing is trying to convert '7' to an integer. gcjr has provided two solutions but the thread title says that you want to convert an array of chars to an int, not single characters