Arduino: String to Int - Sådan gør du
Når du programmerer Arduino er du undertiden nødt til at konvertere strenge til heltal. Du kan finde ud af, hvordan du gør dette i dette praktiske tip
Arduino: String to Int
Så du kan konvertere en streng til et heltal på Arduino, skal du først definere en ny streng med en kommando som »String a =" 23 "«.
- For at konvertere denne streng til et heltal, har du brug for en heltalvariabel. Du kan også automatisk tildele den korrekte værdi til den.
- Du kan gøre dette med kommandoen »int b = atoi (a);«. Variablen "b" har nu værdien 23 som et heltal.
- Sørg dog for, at strengen ikke indeholder mellemrum eller bogstaver.
I det næste praktiske tip viser vi dig, hvordan du bygger et voltmeter med Arduino.