Serial.parseFloat() Arduino

Ini adalah contoh program Arduino untuk mengambil data serial dan melakukan parsing berdasarkan tipe da, string, int ataupun float,

  1. String myName; //Declare a String variable to hold your name
  2. int age; //Declare an Int variable to hold your age
  3. float height; //Declare a float variable to hold your height
  4. void setup() {
  5. Serial.begin(9600); // turn on Serial Port
  6. }
  7. void loop() {
  8. Serial.println(“Please enter your name: “); //Prompt User for input
  9. while (Serial.available()==0) { //Wait for user input
  10. }
  11. myName=Serial.readString(); //Read user input into myName
  12. Serial.println(“How old are you? “); //Prompt User for input
  13. while (Serial.available()==0) {
  14. }
  15. age=Serial.parseInt(); //Read user input into age
  16. Serial.println(“How tall are you? “); //Prompt User for input
  17. while (Serial.available()==0) {
  18. }
  19. height=Serial.parseFloat(); //Read user input into height
  20. Serial.print(“Hello “); //Print out nicely formatted output.
  21. Serial.print(myName);
  22. Serial.print(“, you are “);
  23. Serial.print(age);
  24. Serial.println(” years old,”);
  25. Serial.print(“and you are “);
  26. height=height10;
  27. Serial.print(height);
  28. Serial.println(” feet tall.”);
  29. Serial.println(“”);
  30. }

summer: http://www.toptechboy.com/arduino/lesson-12-simple-and-easy-way-to-read-strings-ints-and-floats-over-arduino-serial-port/#sthash.yCjv7Jn2.dpuf

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s