-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathStringToFloat.ino
More file actions
39 lines (28 loc) · 1.07 KB
/
StringToFloat.ino
File metadata and controls
39 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
StringToFloat.ino - String to Float conversion
Since the string.toFloat() function is not supported in the Edison boards, this example shows how to
perform this conversion using another way.
This example code is in the public domain.
Revision History
----------------------------------------------------------
Author Date Description
----------------------------------------------------------
Diego Villalobos 06-09-2015 Example created
*/
String stringValue = ""; // String to be converted
void setup() {
Serial.begin(9600);
delay(3000);
Serial.println("This example shows an alternative way to convert");
Serial.println("a string value into a float value in the Edison boards.");
}
void loop() {
stringValue = "-0.5527153";
Serial.println("String value: " + stringValue);
char floatbuf[32]; // Make this buffer at least enough for the whole string.
stringValue.toCharArray(floatbuf, sizeof(floatbuf));
float floatValue = atof(floatbuf);
Serial.print("Float value: ");
Serial.println(floatValue);
delay(5000);
}