Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Serial Integer Writer, by Pedro Tome'
- * Version 0.01
- *
- * Writes/sends integer numbers to the Serial buffer by converting them
- * into an ASCII string.
- *
- * Use this code if you want to send integer values to another Arduino,
- * which should have the Serial Integer Reader code, by Pedro Tome'.
- *
- * Example:
- * A temperature sensor reads the value decValue = 1234.
- * The ASCII string "1234" will be sent to the Serial buffer.
- *
- * The maximum value is 65535 due to "decValue" being an unsigned int.
- */
- #include <Stdio.h>
- int TXpin = 1;
- char sentString[6]; // the ASCII string array that will be sent via Serial
- void setup(){
- Serial.begin(9600);
- pinMode(TXpin, OUTPUT);
- }
- void loop(){
- unsigned int decValue = 1234; // a decimal number. Example: the reading of a sensor
- /* convert the number to an ASCII string array */
- // each digit is converted into it's respective ASCII value
- // and is stored in sentString.
- sprintf(sentString, "%d", decValue);
- Serial.print(sentString);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement