Serial.Print History

Hide minor edits - Show changes to markup

May 31, 2010, at 07:04 PM by Equipo Traduccion -
Changed lines 5-25 from:

Description

Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is. For example:

  • Serial.print(78) gives "78"
  • Serial.print(1.23456) gives "1.23"
  • Serial.print(byte(78)) gives "N" (whose ASCII value is 78)
  • Serial.print('N') gives "N"
  • Serial.print("Hello world.") gives "Hello world."

An optional second parameter specifies the base (format) to use; permitted values are BYTE, BIN (binary, or base 2), OCT (octal, or base 8), DEC (decimal, or base 10), HEX (hexadecimal, or base 16). For floating point numbers, this parameter specifies the number of decimal places to use. For example:

  • Serial.print(78, BYTE) gives "N"
  • Serial.print(78, BIN) gives "1001110"
  • Serial.print(78, OCT) gives "116"
  • Serial.print(78, DEC) gives "78"
  • Serial.print(78, HEX) gives "4E"
  • Serial.println(1.23456, 0) gives "1"
  • Serial.println(1.23456, 2) gives "1.23"
  • Serial.println(1.23456, 4) gives "1.2346"

Syntax

to:

Descripción

Imprime los datos al puerto serie como texto ASCII. Este comando puede tomar muchas formas. Los números son impresos mediante un juego de caracteres ASCII para cada dígito. Los valores de tipo "float" son impresos en forma de dígitos ASCII con dos decimales por defecto. Los valores tipo "byte" se envían como un único carácter. Los caracteres y las cadenas se envían tal cual. Por ejemplo:

  • Serial.print(78) imprime "78"
  • Serial.print(1.23456) imprime "1.23"
  • Serial.print(byte(78)) imprime "N" (cuyo código ASCII es 78)
  • Serial.print('N') imprime "N"
  • Serial.print("Hello world.") imprime "Hello world."

Un segundo parámetro opcional especifica la base (formato) a usar; los valores permitidos son BYTE, BIN (binarios o base 2), OCT (octales o base 8), DEC (decimales o base 10), HEX (hexadecimales o base 16). Para números de coma flotante, este parámetro especifica el numero de posiciones decimales a usar. Por ejemplo:

  • Serial.print(78, BYTE) imprime "N"
  • Serial.print(78, BIN) imprime "1001110"
  • Serial.print(78, OCT) imprime "116"
  • Serial.print(78, DEC) imprime "78"
  • Serial.print(78, HEX) imprime "4E"
  • Serial.println(1.23456, 0) imprime "1"
  • Serial.println(1.23456, 2) imprime "1.23"
  • Serial.println(1.23456, 4) imprime "1.2346"

Sintaxis

Changed lines 31-41 from:

Parameters

val: the value to print - any data type

format: specifies the number base (for integral data types) or number of decimal places (for floating point types)

Returns

None

Example:

to:

Parámetros

val: el valor a imprimir - de cualquier tipo

format: especifica el número de la base (para números enteros) o el número de posiciones decimales (para números de coma flotante o tipo "float")

Devuelve

Nada

Ejemplo:

Changed line 43 from:

Uses a FOR loop for data and prints a number in various formats.

to:

Usa un bucle FOR para los datos e imprime un número en varios formatos.

Changed line 48 from:
  Serial.begin(9600);      // open the serial port at 9600 bps:    
to:
  Serial.begin(9600);      // abre el puerto serie a 9600 bps:    
Changed lines 53-55 from:
  Serial.print("NO FORMAT");       // prints a label
  Serial.print("\t");              // prints a tab
to:
  Serial.print("SIN FORMATO");       // imprime un texto
  Serial.print("\t");              // imprime un tabulado
Changed lines 70-90 from:
  for(x=0; x< 64; x++){    // only part of the ASCII chart, change to suit

    // print it out in many formats:
    Serial.print(x);       // print as an ASCII-encoded decimal - same as "DEC"
    Serial.print("\t");    // prints a tab

    Serial.print(x, DEC);  // print as an ASCII-encoded decimal
    Serial.print("\t");    // prints a tab

    Serial.print(x, HEX);  // print as an ASCII-encoded hexadecimal
    Serial.print("\t");    // prints a tab

    Serial.print(x, OCT);  // print as an ASCII-encoded octal
    Serial.print("\t");    // prints a tab

    Serial.print(x, BIN);  // print as an ASCII-encoded binary
    Serial.print("\t");    // prints a tab

    Serial.println(x, BYTE);    // prints as a raw byte value, 
    //                             then adds the carriage return with "println"
    delay(200);            // delay 200 milliseconds
to:
  for(x=0; x< 64; x++){    // solo una parte de la tabla

    // imprime en varios formatos:
    Serial.print(x);       // imprime como codificado ASCII decimal - igual que "DEC"
    Serial.print("\t");    // imprime un tabulado

    Serial.print(x, DEC);  // imprime como codificado ASCII decimal
    Serial.print("\t");    // imprime un tabulado

    Serial.print(x, HEX);  // imprime como codificado ASCII hexadecimal
    Serial.print("\t");    // imprime un tabulado

    Serial.print(x, OCT);  // imprime como codificado ASCII octal
    Serial.print("\t");    // imprime un tabulado

    Serial.print(x, BIN);  // imprime como codificado ASCII binario
    Serial.print("\t");    // imprime un tabulado

    Serial.println(x, BYTE);    // imprime el valor en bruto del byte, 
    //                             y añade el salto de linea con "println"
    delay(200);            // espera 200 milisegundos
Changed line 92 from:
  Serial.println("");      // prints another carriage return
to:
  Serial.println("");      //imprime otro salto de linea
Changed lines 95-99 from:

Programming Tips / Known Issues

The last character to be printed is transmitted over the serial port after Serial.print() has returned.

See also

to:

Sugerencias de programación / Problemas conocidos

El último carácter a imprimir se transmite a través del puerto serie después de que Serial.print () ha regresado.

Ver también

February 01, 2010, at 07:17 PM by David A. Mellis -
Changed lines 7-8 from:

Prints data to the serial port.

to:

Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is. For example:

  • Serial.print(78) gives "78"
  • Serial.print(1.23456) gives "1.23"
  • Serial.print(byte(78)) gives "N" (whose ASCII value is 78)
  • Serial.print('N') gives "N"
  • Serial.print("Hello world.") gives "Hello world."

An optional second parameter specifies the base (format) to use; permitted values are BYTE, BIN (binary, or base 2), OCT (octal, or base 8), DEC (decimal, or base 10), HEX (hexadecimal, or base 16). For floating point numbers, this parameter specifies the number of decimal places to use. For example:

  • Serial.print(78, BYTE) gives "N"
  • Serial.print(78, BIN) gives "1001110"
  • Serial.print(78, OCT) gives "116"
  • Serial.print(78, DEC) gives "78"
  • Serial.print(78, HEX) gives "4E"
  • Serial.println(1.23456, 0) gives "1"
  • Serial.println(1.23456, 2) gives "1.23"
  • Serial.println(1.23456, 4) gives "1.2346"

Changed lines 26-82 from:

This command can take many forms:

Serial.print(b) with no format specified, prints b as a decimal number in an ASCII string. For example,

int b = 79;
Serial.print(b);

prints the ASCII string "79".

Serial.print(b, DEC) prints b as a decimal number in an ASCII string. For example,

int b = 79;
Serial.print(b, DEC);

prints the string "79".

Serial.print(b, HEX) prints b as a hexadecimal number in an ASCII string. For example,

int b = 79;
Serial.print(b, HEX);

prints the string "4F".

Serial.print(b, OCT) prints b as an octal number in an ASCII string. For example,

int b = 79;
Serial.print(b, OCT);

prints the string "117".

Serial.print(b, BIN) prints b as a binary number in an ASCII string. For example,

int b = 79;
Serial.print(b, BIN);

prints the string "1001111".

Serial.print(b, BYTE) prints b as a single byte. For example,

int b = 79;
Serial.print(b, BYTE);

returns the string "O", which is the ASCII character represented by the value 79. For more information see the ASCII table.

Serial.print(str) if str is a string or an array of chars, prints str as an ASCII string. For example,

Serial.print("Hello World!");

prints the string "Hello World!".

to:

Serial.print(val)
Serial.print(val, format)

Changed lines 30-34 from:

b: the byte to print, or

str: the string to print

to:

val: the value to print - any data type

format: specifies the number base (for integral data types) or number of decimal places (for floating point types)

Changed lines 94-102 from:

Serial.print() doesn't work on floats, so you'll need to cast them to an integral type, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution.

Be careful about doing math inside the brackets e.g.
Serial.print(x-2, DEC);
The unsigned char data type, and byte data type will yield incorrect results and act as though they are signed types i.e. type char.

The Serial.print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the last character.

to:

The last character to be printed is transmitted over the serial port after Serial.print() has returned.

Changed lines 98-105 from:
to:
February 01, 2010, at 05:29 PM by David A. Mellis -
Changed lines 1-2 from:

Serial.print(data)

to:

Serial

print()

Deleted lines 8-13:

Parameter

data: integer types, including char, floats
Printing of floats is supported with a precision of two places to the right of the decimal point.
This may change soon.

July 24, 2009, at 01:18 AM by Paul Badger -
July 24, 2009, at 01:16 AM by Paul Badger -
Changed lines 10-11 from:

Printing of floats is currently supported to two places to the right of the decimal point. This may change soon.

to:

Printing of floats is supported with a precision of two places to the right of the decimal point.
This may change soon.

July 24, 2009, at 01:15 AM by Paul Badger -
Changed lines 9-11 from:

data: integer types, including char, floats printing of floats is currently supported to two places to the right of the decimal point. This may change soon.

to:

data: integer types, including char, floats
Printing of floats is currently supported to two places to the right of the decimal point. This may change soon.

July 24, 2009, at 01:14 AM by Paul Badger -
Changed lines 9-10 from:

data: all integer types, including char

to:

data: integer types, including char, floats printing of floats is currently supported to two places to the right of the decimal point. This may change soon.

October 28, 2008, at 05:36 PM by Paul Badger -
Changed lines 87-88 from:
  Serial.begin(9600);      // open the serial port at 9600 bps:
to:
  Serial.begin(9600);      // open the serial port at 9600 bps:    
October 28, 2008, at 05:30 PM by Paul Badger -
Changed lines 87-88 from:
  // open the serial port at 9600 bps:
  Serial.begin(9600);
to:
  Serial.begin(9600);      // open the serial port at 9600 bps:
October 28, 2008, at 05:29 PM by Paul Badger -
Deleted lines 83-84:
October 28, 2008, at 05:29 PM by Paul Badger -
Changed lines 81-82 from:

[@/*Uses a for loop for data and prints a number in various formats.

to:

[@/* Uses a FOR loop for data and prints a number in various formats.

October 28, 2008, at 05:28 PM by Paul Badger -
Changed line 94 from:
  Serial.print("No FORMAT");       // prints a label
to:
  Serial.print("NO FORMAT");       // prints a label
October 28, 2008, at 05:27 PM by Paul Badger -
Changed lines 81-83 from:

Uses a for loop for data and prints a number in various formats.

[@

to:

[@/*Uses a for loop for data and prints a number in various formats.

  • /

October 28, 2008, at 05:26 PM by Paul Badger -
Added lines 81-82:

Uses a for loop for data and prints a number in various formats.

October 28, 2008, at 05:23 PM by Paul Badger -
Changed lines 82-92 from:

/*

  Analog input

 reads an analog input on analog in 0, prints the value out.

 created 24 March 2006
 by Tom Igoe
 */

int analogValue = 0; // variable to hold the analog value

to:

int x = 0; // variable

Changed lines 89-112 from:

void loop() {

  // read the analog input on pin 0:
  analogValue = analogRead(0);

  // print it out in many formats:
  Serial.print(analogValue);         // print as an ASCII-encoded decimal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, DEC);    // print as an ASCII-encoded decimal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, HEX);    // print as an ASCII-encoded hexadecimal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, OCT);    // print as an ASCII-encoded octal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, BIN);    // print as an ASCII-encoded binary
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the
                                     // value by 4 because analogRead() returns numbers
                                     // from 0 to 1023, but a byte can only hold values
                                     // up to 255)
  Serial.print("\t");                // print a tab character    
  Serial.println();                  // print a linefeed character

  // delay 10 milliseconds before the next reading:
  delay(10);
to:

void loop() {

  // print labels 
  Serial.print("No FORMAT");       // prints a label
  Serial.print("\t");              // prints a tab

  Serial.print("DEC");  
  Serial.print("\t");      

  Serial.print("HEX"); 
  Serial.print("\t");   

  Serial.print("OCT");
  Serial.print("\t");

  Serial.print("BIN");
  Serial.print("\t"); 

  Serial.println("BYTE");

  for(x=0; x< 64; x++){    // only part of the ASCII chart, change to suit

    // print it out in many formats:
    Serial.print(x);       // print as an ASCII-encoded decimal - same as "DEC"
    Serial.print("\t");    // prints a tab

    Serial.print(x, DEC);  // print as an ASCII-encoded decimal
    Serial.print("\t");    // prints a tab

    Serial.print(x, HEX);  // print as an ASCII-encoded hexadecimal
    Serial.print("\t");    // prints a tab

    Serial.print(x, OCT);  // print as an ASCII-encoded octal
    Serial.print("\t");    // prints a tab

    Serial.print(x, BIN);  // print as an ASCII-encoded binary
    Serial.print("\t");    // prints a tab

    Serial.println(x, BYTE);    // prints as a raw byte value, 
    //                             then adds the carriage return with "println"
    delay(200);            // delay 200 milliseconds
  }
  Serial.println("");      // prints another carriage return
October 28, 2008, at 04:58 PM by Paul Badger -
Changed lines 131-133 from:

The Serial.Print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the last character.

to:

The Serial.print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the last character.

November 21, 2007, at 09:50 PM by David A. Mellis - clarifying use with floats.
Changed lines 9-10 from:

data: all integer types, including char; truncates floating point numbers to integers

to:

data: all integer types, including char

Changed lines 125-126 from:

Serial.print() truncates floats into integers, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution.

to:

Serial.print() doesn't work on floats, so you'll need to cast them to an integral type, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution.

September 08, 2007, at 12:47 AM by Paul Badger -
Changed lines 131-133 from:

The Serial.Print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the last character.

to:

The Serial.Print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the last character.

September 08, 2007, at 12:47 AM by Paul Badger -
Changed lines 131-133 from:

The Serial.Print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the !!!last character.

to:

The Serial.Print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the last character.

September 08, 2007, at 12:44 AM by Paul Badger -
Changed line 124 from:

Programming Tip / Known Issues

to:

Programming Tips / Known Issues

Changed lines 131-133 from:
to:

The Serial.Print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the !!!last character.

July 19, 2007, at 05:36 AM by Paul Badger -
Changed lines 60-61 from:

returns the string "O", which is the ASCII character represented by the value 79. See the ASCII table for more.

to:

returns the string "O", which is the ASCII character represented by the value 79. For more information see the ASCII table.

Changed lines 63-64 from:

if str is a string or an array of chars, prints str an ASCII string. For example,

to:

if str is a string or an array of chars, prints str as an ASCII string. For example,

July 19, 2007, at 05:34 AM by Paul Badger -
Changed lines 60-61 from:

returns the string "O", which is the ASII character represented by the value 79. See the ASCII table for more.

to:

returns the string "O", which is the ASCII character represented by the value 79. See the ASCII table for more.

July 19, 2007, at 05:30 AM by Paul Badger -
Changed line 127 from:

Also be careful about doing math inside the brackets e.g.\\

to:

Be careful about doing math inside the brackets e.g.\\

July 19, 2007, at 05:26 AM by Paul Badger -
Changed lines 127-128 from:

Also be careful about doing math inside the brackets e.g. Serial.print(x-2, DEC);

to:

Also be careful about doing math inside the brackets e.g.
Serial.print(x-2, DEC);\\

July 19, 2007, at 05:25 AM by Paul Badger -
Changed lines 124-127 from:

Programming Tip

Serial.print() truncates floats into integers, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution. Just remember to convert it back on the other end before your project is launched on the Hubble Space Telescope.

to:

Programming Tip / Known Issues

Serial.print() truncates floats into integers, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution.

Also be careful about doing math inside the brackets e.g. Serial.print(x-2, DEC); The unsigned char data type, and byte data type will yield incorrect results and act as though they are signed types i.e. type char.

May 30, 2007, at 06:23 PM by Paul Badger -
Changed line 130 from:
to:
May 30, 2007, at 06:22 PM by Paul Badger -
Added lines 129-130:
April 14, 2007, at 07:37 AM by Paul Badger -
Changed lines 15-16 from:

prints b as a decimal number in an ASCII string. For example,

to:

with no format specified, prints b as a decimal number in an ASCII string. For example,

Changed lines 20-21 from:

with no specified format, defaults to decimal, and prints the ASCII string "79".

to:

prints the ASCII string "79".

April 14, 2007, at 07:33 AM by Paul Badger -
Changed lines 20-21 from:

prints the string "79".

to:

with no specified format, defaults to decimal, and prints the ASCII string "79".

April 14, 2007, at 07:30 AM by Paul Badger -
Added line 11:

Syntax

April 14, 2007, at 07:29 AM by Paul Badger -
Changed lines 9-10 from:

data

to:

data: all integer types, including char; truncates floating point numbers to integers

April 14, 2007, at 07:26 AM by Paul Badger -
Changed lines 5-6 from:

Prints a data to the serial port. This command can take many forms:

to:

Prints data to the serial port.

Parameter

data

This command can take many forms:

April 14, 2007, at 07:19 AM by Paul Badger -
Changed lines 115-117 from:

}

@]

to:

}@]

April 14, 2007, at 07:18 AM by Paul Badger -
Changed lines 119-121 from:

Serial.print() truncates floats into integers, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution. Just remember to convert it back on the other end before your project is launched on the Hubble.

to:

Serial.print() truncates floats into integers, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution. Just remember to convert it back on the other end before your project is launched on the Hubble Space Telescope.

April 14, 2007, at 07:17 AM by Paul Badger -
Changed lines 118-121 from:
to:

Programming Tip

Serial.print() truncates floats into integers, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution. Just remember to convert it back on the other end before your project is launched on the Hubble.

March 28, 2006, at 11:14 AM by David A. Mellis - Reformatted example (dividing analogValue by 4 when sending as single byte).
Changed lines 96-109 from:
  Serial.print(analogValue);       // print as an ASCII-encoded decimal
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, DEC);  // print as an ASCII-encoded decimal
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, HEX);  // print as an ASCII-encoded hexadecimal
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, OCT);  // print as an ASCII-encoded octal
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, BIN);  // print as an ASCII-encoded binary
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the value by 4 because analogRead() returns numbers from 0 to 1023, but a byte can only hold values up to 255)
  Serial.print("\t");              // print a tab character    
  Serial.println();                // print a linefeed character
to:
  Serial.print(analogValue);         // print as an ASCII-encoded decimal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, DEC);    // print as an ASCII-encoded decimal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, HEX);    // print as an ASCII-encoded hexadecimal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, OCT);    // print as an ASCII-encoded octal
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue, BIN);    // print as an ASCII-encoded binary
  Serial.print("\t");                // print a tab character
  Serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the
                                     // value by 4 because analogRead() returns numbers
                                     // from 0 to 1023, but a byte can only hold values
                                     // up to 255)
  Serial.print("\t");                // print a tab character    
  Serial.println();                  // print a linefeed character
March 28, 2006, at 11:11 AM by David A. Mellis - Changed "returns the string ..." to "prints the string ..."
Changed lines 13-14 from:

returns the string "79".

to:

prints the string "79".

Changed lines 21-22 from:

returns the string "79".

to:

prints the string "79".

Changed lines 29-30 from:

returns the string "4F".

to:

prints the string "4F".

Changed lines 37-38 from:

returns the string "117".

to:

prints the string "117".

Changed lines 45-46 from:

returns the string "1001111".

to:

prints the string "1001111".

Changed lines 60-61 from:

returns the string "Hello World!".

to:

prints the string "Hello World!".

Changed line 106 from:
  Serial.print(analogValue, BYTE); // print as a raw byte value
to:
  Serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the value by 4 because analogRead() returns numbers from 0 to 1023, but a byte can only hold values up to 255)
March 27, 2006, at 08:58 PM by Tom Igoe -
Deleted lines 113-114:
Changed lines 117-119 from:

to:
March 27, 2006, at 08:55 PM by Tom Igoe -
Changed lines 53-54 from:

returns the string "O", which is the ASII character represented by the value 79. See the ASCII table for more..

to:

returns the string "O", which is the ASII character represented by the value 79. See the ASCII table for more.

March 27, 2006, at 08:54 PM by Tom Igoe -
Changed line 52 from:

Serial.print(b, BIN);@]

to:

Serial.print(b, BYTE);@]

March 27, 2006, at 08:53 PM by Tom Igoe -
Changed lines 47-49 from:

Serial.print(str) if str is a string or an array of chars, prints str an ASCII string. For example,

to:

Serial.print(b, BYTE) prints b as a single byte. For example,

Added lines 51-58:

int b = 79; Serial.print(b, BIN);@] returns the string "O", which is the ASII character represented by the value 79. See the ASCII table for more..

Serial.print(str) if str is a string or an array of chars, prints str an ASCII string. For example,

[@

March 27, 2006, at 08:45 PM by Tom Igoe -
March 27, 2006, at 08:43 PM by Tom Igoe -
Changed lines 48-49 from:

IF str is a string or an array of chars, prints str an ASCII string. For example,

to:

if str is a string or an array of chars, prints str an ASCII string. For example,

March 27, 2006, at 08:43 PM by Tom Igoe -
Changed line 88 from:
  Serial.print(analogValue);      // print as an ASCII-encoded decimal
to:
  Serial.print(analogValue);       // print as an ASCII-encoded decimal
March 27, 2006, at 08:43 PM by Tom Igoe -
Changed line 88 from:
  Serial.print(analogValue,);      // print as an ASCII-encoded decimal
to:
  Serial.print(analogValue);      // print as an ASCII-encoded decimal
March 27, 2006, at 08:43 PM by Tom Igoe -
Added line 89:
  Serial.print("\t");              // print a tab character
March 27, 2006, at 08:42 PM by Tom Igoe -
Added line 88:
  Serial.print(analogValue,);      // print as an ASCII-encoded decimal
March 27, 2006, at 08:42 PM by Tom Igoe -
Changed line 7 from:

Serial.print(b, DEC)

to:

Serial.print(b)

Changed line 12 from:

Serial.print(b, DEC);@]

to:

Serial.print(b);@]

Changed lines 15-17 from:

Serial.print(int b, HEX) prints b as a hexadecimal number in an ASCII string. For example,

to:

Serial.print(b, DEC) prints b as a decimal number in an ASCII string. For example,

Added lines 20-27:

Serial.print(b, DEC);@] returns the string "79".

Serial.print(b, HEX) prints b as a hexadecimal number in an ASCII string. For example,

[@ int b = 79;

March 27, 2006, at 08:41 PM by Tom Igoe -
Changed line 7 from:

Serial.print(int b, DEC)

to:

Serial.print(b, DEC)

Changed line 23 from:

Serial.print(int b, OCT)

to:

Serial.print(b, OCT)

Changed line 31 from:

Serial.print(int b, BIN)

to:

Serial.print(b, BIN)

March 27, 2006, at 08:40 PM by Tom Igoe -
Changed lines 89-90 from:
  Serial.print("\t");              // print a tab character
    Serial.print(analogValue);      
to:
  Serial.print("\t");              // print a tab character    
March 27, 2006, at 08:39 PM by Tom Igoe -
Added lines 56-100:

Example:

/*
  Analog input

 reads an analog input on analog in 0, prints the value out.

 created 24 March 2006
 by Tom Igoe
 */

int analogValue = 0;    // variable to hold the analog value

void setup() {
  // open the serial port at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog input on pin 0:
  analogValue = analogRead(0);

  // print it out in many formats:
  Serial.print(analogValue, DEC);  // print as an ASCII-encoded decimal
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, HEX);  // print as an ASCII-encoded hexadecimal
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, OCT);  // print as an ASCII-encoded octal
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, BIN);  // print as an ASCII-encoded binary
  Serial.print("\t");              // print a tab character
  Serial.print(analogValue, BYTE); // print as a raw byte value
  Serial.print("\t");              // print a tab character
    Serial.print(analogValue);      
  Serial.println();                // print a linefeed character

  // delay 10 milliseconds before the next reading:
  delay(10);
}




March 27, 2006, at 08:38 PM by Tom Igoe -
Changed lines 28-29 from:

Serial.print(b, OCT); @]

to:

Serial.print(b, OCT);@]

Changed lines 36-37 from:

Serial.print(b, BIN); @]

to:

Serial.print(b, BIN);@]

Changed lines 43-44 from:

Serial.print("Hello World!"); @]

to:

Serial.print("Hello World!");@]

Changed lines 57-59 from:

to:

March 27, 2006, at 08:38 PM by Tom Igoe -
Changed lines 12-13 from:

Serial.print(b, DEC); @]

to:

Serial.print(b, DEC);@]

Changed lines 20-21 from:

Serial.print(b, HEX); @]

to:

Serial.print(b, HEX);@]

March 27, 2006, at 08:38 PM by Tom Igoe -
Added lines 43-50:

Serial.print(str) IF str is a string or an array of chars, prints str an ASCII string. For example,

Serial.print("Hello World!");

returns the string "Hello World!".

March 27, 2006, at 08:36 PM by Tom Igoe -
Deleted line 13:
Deleted line 22:
Deleted line 31:
Deleted line 40:
Changed lines 45-46 from:

b: the byte to print

to:

b: the byte to print, or

str: the string to print

Changed lines 54-63 from:
to:
March 27, 2006, at 08:35 PM by Tom Igoe -
Added lines 1-65:

Serial.print(data)

Description

Prints a data to the serial port. This command can take many forms:

Serial.print(int b, DEC) prints b as a decimal number in an ASCII string. For example,

int b = 79;
Serial.print(b, DEC);

returns the string "79".

Serial.print(int b, HEX) prints b as a hexadecimal number in an ASCII string. For example,

int b = 79;
Serial.print(b, HEX);

returns the string "4F".

Serial.print(int b, OCT) prints b as an octal number in an ASCII string. For example,

int b = 79;
Serial.print(b, OCT);

returns the string "117".

Serial.print(int b, BIN) prints b as a binary number in an ASCII string. For example,

int b = 79;
Serial.print(b, BIN);

returns the string "1001111".

Parameters

b: the byte to print

Returns

None

See also

Reference Home?

Share