LONG to STRING
Conversion d’un entier de type long non signé en chaîne de caractère :
Unsigned Long peut stocker un nombre entier allant de 0 à 4 294 967 295. Le convertir en chaîne facilite son affichage et/ou sa transmission via une communication entre deux Arduinos.
String long2string(unsigned long longint) {
char buf[10];
int len = 0;
String temp;
String left;
String right;
ltoa(longint, buf, 10);
temp = buf;
len = temp.length();
switch (len) {
case 1:
temp = "000 00" + temp;
break;
case 2:
temp = "000 0" + temp;
break;
case 3:
temp = "000 " + temp;
break;
case 4:
temp = "00" + temp;
left = temp.substring(0, 3);
right = temp.substring(3, 6);
temp = left + " " + right;
break;
case 5:
temp = "0" + temp;
left = temp.substring(0, 3);
right = temp.substring(3, 6);
temp = left + " " + right;
break;
case 6:
left = temp.substring(0, 3);
right = temp.substring(3, 6);
temp = left + " " + right;
break;
default:
temp = "000 000";
break;
}
return temp;
}
Un code exemple peut être téléchargé ici
STRING to LONG
String inString = "10:20"; int nHeure, nSec; int FirstIndex = inString.indexOf(':'); String firstValue = inString.substring(0, FirstIndex); String secondValue = inString.substring(FirstIndex + 1); Serial.println(firstValue); nHeure = firstValue.toInt(); Serial.println(nHeure); Serial.println(secondValue); nSec = secondValue.toInt(); Serial.println(nSec);
https://www.arduino.cc/en/Reference/StringToInt
Références sur les types de variables :
http://www.mon-club-elec.fr/pmwiki_reference_arduino/pmwiki.php?n=Main.UnsignedLong