Advertisement
Guest User

Serial Integer Writer

a guest
Sep 1st, 2010
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /*
  2. * Serial Integer Writer, by Pedro Tome'
  3. * Version 0.01
  4. *
  5. * Writes/sends integer numbers to the Serial buffer by converting them
  6. * into an ASCII string.
  7. *
  8. * Use this code if you want to send integer values to another Arduino,
  9. * which should have the Serial Integer Reader code, by Pedro Tome'.
  10. *
  11. * Example:
  12. * A temperature sensor reads the value decValue = 1234.
  13. * The ASCII string "1234" will be sent to the Serial buffer.
  14. *
  15. * The maximum value is 65535 due to "decValue" being an unsigned int.
  16. */
  17.  
  18.  
  19. #include <Stdio.h>
  20.  
  21. int TXpin = 1;
  22. char sentString[6]; // the ASCII string array that will be sent via Serial
  23.  
  24. void setup(){
  25. Serial.begin(9600);
  26. pinMode(TXpin, OUTPUT);
  27. }
  28.  
  29. void loop(){
  30. unsigned int decValue = 1234; // a decimal number. Example: the reading of a sensor
  31.  
  32. /* convert the number to an ASCII string array */
  33. // each digit is converted into it's respective ASCII value
  34. // and is stored in sentString.
  35. sprintf(sentString, "%d", decValue);
  36.  
  37. Serial.print(sentString);
  38. delay(1000);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement