Advertisement
RuiViana

String to int

Nov 12th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. /**
  2. * getInt.cpp
  3. * Converts numerical string into an integer
  4. *
  5. * Author: Marcelo Shiniti Uchimura
  6. * When: Jan '09
  7. */
  8. byte incomingByte = 0; // for incoming serial data
  9. int value = 0; // for storing the input decimal value
  10.  
  11. void setup() {
  12. Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  13. }
  14.  
  15. void loop() {
  16. // send data only when you receive data:
  17. if (Serial.available() > 0) {
  18. // read the incoming byte:
  19. incomingByte = Serial.read();
  20. if(incomingByte == 13) {
  21. Serial.println();
  22. Serial.println(value, DEC);
  23. value = 0;
  24. }
  25. else
  26. value = value * 10 + incomingByte - 0x30;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement