Tutorial.Dimmer History

Hide minor edits - Show changes to markup

June 05, 2010, at 10:41 AM by Equipo Traduccion -
Changed lines 38-39 from:
 /* Processing code for this example */
  // Dimmer - sends bytes over a serial port
to:
 /* Código Processing para este ejemplo */
  // Atenuador - envía bytes a traves del puerto serie
Changed lines 42-43 from:
  // This example code is in the public domain.
to:
  // Este ejemplo es de dominio público.
Changed line 50 from:
  println("Available serial ports:");
to:
  println("Puertos serie disponibles:");
Changed lines 53-57 from:
  // Uses the first port in this list (number 0).  Change this to
  // select the port corresponding to your Arduino board.  The last
  // parameter (e.g. 9600) is the speed of the communication.  It
  // has to correspond to the value passed to Serial.begin() in your
  // Arduino sketch.
to:
  // Utiliza el primer puerto disponible de la lista (numero 0).  Cambia esto para
  // seleccionar el puerto correspondiente a tu placa Arduino board.  El último
  // parámetro (ej. 9600) es la velocidad de la comunicación.  Debe
  // corresponder con el valor pasado a Serial.begin() en el
  // programa (sketch) Arduino.
Changed lines 60-61 from:
  // If you know the name of the port used by the Arduino board, you
  // can specify it directly like this.
to:
  // Si conoces el nombre del puerto usado por la placa Arduino, puedes
  // especificarlo directamente aquí si quieres.
Changed line 66 from:
  // draw a gradient from black to white
to:
  // traza un gradiente de negro a blanco
Changed lines 72-73 from:
  // write the current X-position of the mouse to the serial port as
  // a single byte
to:
  // escribe la posición actual del ratón por el puerto serie
  // como un byte simple
Changed lines 79-82 from:

Max code

The Max/MSP patch looks like the image below. The text of the patch is linked behind the image. Copy it and paste it into a new patch window.

to:

Código de Max

El programa (patch) de Max/MSP se parece a la imagen de debajo. El código del programa está vinculado a la imagen. Cópialo y pégalo en una ventana de nuevo programa.

June 05, 2010, at 10:28 AM by Equipo Traduccion -
Changed lines 16-22 from:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic

click the image to enlarge

to:

imagen desarrollada utilizando Fritzing. Para mas circuitos de ejemplo, visita la página del proyecto Fritzing

Esquema

haz click en la imagen para ampliarla

Changed lines 33-37 from:

Processing Code

Run the following sketch in Processing. It will send bytes out the serial port to the Arduino to dim the LED.

to:

Código para Processing

Ejecuta el siguiente programa (sketch) en Processing. Envía bytes por el puerto serie al Arduino para atenuar el LED.

June 05, 2010, at 10:23 AM by Equipo Traduccion -
Changed lines 1-13 from:

Examples > Communication

Dimmer

Demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of an LED. The data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the brightness of the LED.

You can send bytes to the Arduino from any software that can access the computer serial port. Examples for Processing and Max/MSP version 5 are shown below.

Circuit

An LED connected to pin 9. use appropriate resistor as needed. For most common LEDs, you can usually do without the resistor, as the current output of the digital I/O pins is limited.

click the image to enlarge

to:

Ejemplos > Comunicación

Atenuador (Dimmer)

Muestra el envío de datos desde el ordenador a la placa Arduino, en este caso para controlar el brillo de un LED. Los datos se envían en bytes individuales, cada uno de ellos oscila entre 0 y 255. Arduino lee estos bytes y los utiliza para ajustar el brillo de los LED.

Puedes enviar bytes al Arduino desde cualquier software que tenga acceso al puerto serie del ordenador. Puedes ver ejemplos para Processing y Max/MSP versión 5 mas abajo.

Circuito

Un LED conectado al pin 9 utilizando la resistencia adecuada, según sea necesario. Para la mayoría de los LEDs comunes, generalmente se puede prescindir de la resistencia, ya que la corriente de salida de los pines de E/S digitales es limitada.

haz click en la imagen para ampliarla

February 23, 2010, at 08:09 PM by Tom Igoe -
Changed lines 29-30 from:
 /*
   Dimmer
to:
Changed lines 42-45 from:
  Demonstrates the sending data from the computer to the Arduino board,
  in this case to control the brightness of an LED.  The data is sent
  in individual bytes, each of which ranges from 0 to 255.  Arduino
  reads these bytes and uses them to set the brightness of the LED.
to:
  // This example code is in the public domain.

  import processing.serial.*;
  Serial port;
Changed lines 47-49 from:
  The circuit:
  LED attached from digital pin 9 to ground.
  Serial connection to Processing, Max/MSP, or another serial application
to:
  void setup() {
  size(256, 150);
Changed lines 50-53 from:
  created 2006
  by David A. Mellis
  modified 14 Apr 2009
  by Tom Igoe and Scott Fitzgerald
to:
  println("Available serial ports:");
  println(Serial.list());
Changed lines 53-75 from:
  http://www.arduino.cc/en/Tutorial/Dimmer
to:
  // Uses the first port in this list (number 0).  Change this to
  // select the port corresponding to your Arduino board.  The last
  // parameter (e.g. 9600) is the speed of the communication.  It
  // has to correspond to the value passed to Serial.begin() in your
  // Arduino sketch.
  port = new Serial(this, Serial.list()[0], 9600);  
  
  // If you know the name of the port used by the Arduino board, you
  // can specify it directly like this.
  //port = new Serial(this, "COM1", 9600);
  }
  
  void draw() {
  // draw a gradient from black to white
  for (int i = 0; i < 256; i++) {
  stroke(i);
  line(i, 0, i, 150);
  }
  
  // write the current X-position of the mouse to the serial port as
  // a single byte
  port.write(mouseX);
  }
Changed lines 78-145 from:
to:
August 27, 2009, at 08:55 PM by Tom Igoe -
Changed lines 16-18 from:
to:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

July 05, 2009, at 07:33 PM by Tom Igoe -
Changed line 76 from:
 /* Processing code for this example
to:
 /* Processing code for this example */
July 05, 2009, at 07:31 PM by Tom Igoe -
Changed lines 25-28 from:

[@ /*

  Dimmer
to:
Changed lines 47-50 from:
 Demonstrates the sending data from the computer to the Arduino board,
 in this case to control the brightness of an LED.  The data is sent
 in individual bytes, each of which ranges from 0 to 255.  Arduino
 reads these bytes and uses them to set the brightness of the LED.
to:
 const int ledPin = 9;      // the pin that the LED is attached to
Changed lines 49-51 from:
 The circuit:
 LED attached from digital pin 9 to ground.
 Serial connection to Processing, Max/MSP, or another serial application
to:
 void setup()
 {
   // initialize the serial communication:
   Serial.begin(9600);
   // initialize the ledPin as an output:
   pinMode(ledPin, OUTPUT);
 }
Changed lines 57-60 from:
 created 2006
 by David A. Mellis
 modified 14 Apr 2009
 by Tom Igoe and Scott Fitzgerald
to:
 void loop() {
   byte brightness;
Changed lines 60-86 from:
 http://www.arduino.cc/en/Tutorial/Dimmer
 */

const int ledPin = 9; // the pin that the LED is attached to

void setup() {

  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);

}

void loop() {

  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
  }

}

@]

to:
Changed lines 75-113 from:
// Dimmer - sends bytes over a serial port
// by David A. Mellis

import processing.serial.*;
Serial port;

void setup() {
  size(256, 150);

  println("Available serial ports:");
  println(Serial.list());

  // Uses the first port in this list (number 0).  Change this to
  // select the port corresponding to your Arduino board.  The last
  // parameter (e.g. 9600) is the speed of the communication.  It
  // has to correspond to the value passed to Serial.begin() in your
  // Arduino sketch.
  port = new Serial(this, Serial.list()[0], 9600);  

  // If you know the name of the port used by the Arduino board, you
  // can specify it directly like this.
  //port = new Serial(this, "COM1", 9600);
}

void draw() {
  // draw a gradient from black to white
  for (int i = 0; i < 256; i++) {
    stroke(i);
    line(i, 0, i, 150);
  }

  // write the current X-position of the mouse to the serial port as
  // a single byte
  port.write(mouseX);
}

to:
 /* Processing code for this example
  // Dimmer - sends bytes over a serial port
  // by David A. Mellis
  
  import processing.serial.*;
  Serial port;
  
  void setup() {
  size(256, 150);
  
  println("Available serial ports:");
  println(Serial.list());
  
  // Uses the first port in this list (number 0).  Change this to
  // select the port corresponding to your Arduino board.  The last
  // parameter (e.g. 9600) is the speed of the communication.  It
  // has to correspond to the value passed to Serial.begin() in your
  // Arduino sketch.
  port = new Serial(this, Serial.list()[0], 9600);  
  
  // If you know the name of the port used by the Arduino board, you
  // can specify it directly like this.
  //port = new Serial(this, "COM1", 9600);
  }
  
  void draw() {
  // draw a gradient from black to white
  for (int i = 0; i < 256; i++) {
  stroke(i);
  line(i, 0, i, 150);
  }
  
  // write the current X-position of the mouse to the serial port as
  // a single byte
  port.write(mouseX);
  }
  */

June 25, 2009, at 11:20 PM by Tom Igoe -
Changed lines 47-48 from:
  1. define ledPin 9 // the pin that the LED is attached to
to:

const int ledPin = 9; // the pin that the LED is attached to

June 25, 2009, at 11:15 PM by Tom Igoe -
Changed lines 21-23 from:

to:

June 25, 2009, at 11:15 PM by Tom Igoe -
Changed lines 12-13 from:

click the image to enlarge

to:

click the image to enlarge

Changed lines 17-23 from:
to:

Schematic

click the image to enlarge

April 16, 2009, at 07:51 PM by Tom Igoe -
Changed lines 10-14 from:

An LED connected to pin 9 (use appropriate resistor as needed).

to:

An LED connected to pin 9. use appropriate resistor as needed. For most common LEDs, you can usually do without the resistor, as the current output of the digital I/O pins is limited.

click the image to enlarge

April 15, 2009, at 11:34 PM by Tom Igoe -
Changed lines 11-12 from:
to:
April 15, 2009, at 11:33 PM by Tom Igoe -
Changed lines 11-12 from:
to:
April 15, 2009, at 11:32 PM by Tom Igoe -
Changed lines 11-12 from:
to:
April 15, 2009, at 11:32 PM by Tom Igoe -
Changed lines 13-14 from:

An LED connected to pin 9 (with appropriate resistor).

to:

An LED connected to pin 9 (use appropriate resistor as needed).

April 15, 2009, at 11:31 PM by Tom Igoe -
Changed lines 11-12 from:
to:
April 15, 2009, at 11:31 PM by Tom Igoe -
Added lines 11-12:
April 15, 2009, at 11:02 PM by Tom Igoe -
Changed lines 105-106 from:

The Max/MSP patch looks like the image below. copy it and paste it into a new patch window.

to:

The Max/MSP patch looks like the image below. The text of the patch is linked behind the image. Copy it and paste it into a new patch window.

April 15, 2009, at 11:02 PM by Tom Igoe -
Changed lines 107-111 from:
to:

April 15, 2009, at 11:01 PM by Tom Igoe -
Changed lines 107-111 from:
to:
April 15, 2009, at 11:01 PM by Tom Igoe -
Changed lines 107-111 from:
to:
April 15, 2009, at 10:59 PM by Tom Igoe -
Changed lines 105-390 from:

The Max/MSP patch looks like the image below. The text of the patch is below, copy it and paste it into a new patch window.


{
	"boxes" : [ 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "Dimmer\n\nThis patch sends a binary number from 0 to 255 out the serial port to an Arduino connected to the port.  It dims an LED attached to the Arduino.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
				"linecount" : 10,
				"patching_rect" : [ 209.0, 55.0, 344.0, 144.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-32",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "change the slider to alter the brightness of the LED",
				"linecount" : 3,
				"patching_rect" : [ 90.0, 235.0, 117.0, 48.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-7",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "number",
				"patching_rect" : [ 215.0, 385.0, 50.0, 19.0 ],
				"numoutlets" : 2,
				"fontsize" : 10.0,
				"outlettype" : [ "int", "bang" ],
				"id" : "obj-6",
				"fontname" : "Verdana",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "slider",
				"patching_rect" : [ 215.0, 235.0, 20.0, 140.0 ],
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"bgcolor" : [ 0.94902, 0.94902, 0.94902, 0.0 ],
				"id" : "obj-1",
				"size" : 256.0,
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "select 0 1",
				"patching_rect" : [ 342.0, 305.0, 62.0, 20.0 ],
				"numoutlets" : 3,
				"fontsize" : 12.0,
				"outlettype" : [ "bang", "bang", "" ],
				"id" : "obj-30",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "click here to close the serial port",
				"patching_rect" : [ 390.0, 396.0, 206.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-26",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "click here to open the serial port",
				"patching_rect" : [ 415.0, 370.0, 206.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-27",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "close",
				"patching_rect" : [ 342.0, 396.0, 39.0, 18.0 ],
				"numoutlets" : 1,
				"fontsize" : 12.0,
				"outlettype" : [ "" ],
				"id" : "obj-21",
				"fontname" : "Arial",
				"numinlets" : 2
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "port a",
				"patching_rect" : [ 364.0, 370.0, 41.0, 18.0 ],
				"numoutlets" : 1,
				"fontsize" : 12.0,
				"outlettype" : [ "" ],
				"id" : "obj-19",
				"fontname" : "Arial",
				"numinlets" : 2
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "Click here to get a list of serial ports",
				"patching_rect" : [ 435.0, 344.0, 207.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-2",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "toggle",
				"patching_rect" : [ 342.0, 268.0, 15.0, 15.0 ],
				"numoutlets" : 1,
				"outlettype" : [ "int" ],
				"id" : "obj-11",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "print",
				"patching_rect" : [ 384.0, 344.0, 36.0, 18.0 ],
				"numoutlets" : 1,
				"fontsize" : 12.0,
				"outlettype" : [ "" ],
				"id" : "obj-13",
				"fontname" : "Arial",
				"numinlets" : 2
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "serial a 9600",
				"patching_rect" : [ 259.0, 420.0, 84.0, 20.0 ],
				"numoutlets" : 2,
				"fontsize" : 12.0,
				"outlettype" : [ "int", "" ],
				"id" : "obj-14",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "Click to start",
				"patching_rect" : [ 369.0, 268.0, 117.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-17",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "panel",
				"patching_rect" : [ 215.0, 235.0, 21.0, 139.0 ],
				"numoutlets" : 0,
				"mode" : 1,
				"grad1" : [ 1.0, 1.0, 1.0, 1.0 ],
				"id" : "obj-8",
				"grad2" : [ 0.509804, 0.509804, 0.509804, 1.0 ],
				"numinlets" : 1,
				"angle" : 270.0
			}

		}
 ],
	"lines" : [ 		{
			"patchline" : 			{
				"source" : [ "obj-11", 0 ],
				"destination" : [ "obj-30", 0 ],
				"hidden" : 0,
				"midpoints" : [ 351.0, 296.0, 351.5, 296.0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-30", 1 ],
				"destination" : [ "obj-19", 0 ],
				"hidden" : 0,
				"midpoints" : [  ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-30", 0 ],
				"destination" : [ "obj-21", 0 ],
				"hidden" : 0,
				"midpoints" : [  ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-21", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 351.5, 416.5, 268.5, 416.5 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-19", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 373.5, 393.5, 268.5, 393.5 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-13", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 393.5, 365.5, 268.5, 365.5 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-1", 0 ],
				"destination" : [ "obj-6", 0 ],
				"hidden" : 0,
				"midpoints" : [  ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-6", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 224.5, 411.5, 268.5, 411.5 ]
			}

		}
 ]
}

to:

The Max/MSP patch looks like the image below. copy it and paste it into a new patch window.

April 15, 2009, at 10:56 PM by Tom Igoe -
Deleted lines 102-104:

Output

Changed lines 105-390 from:
to:

The Max/MSP patch looks like the image below. The text of the patch is below, copy it and paste it into a new patch window.


{
	"boxes" : [ 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "Dimmer\n\nThis patch sends a binary number from 0 to 255 out the serial port to an Arduino connected to the port.  It dims an LED attached to the Arduino.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
				"linecount" : 10,
				"patching_rect" : [ 209.0, 55.0, 344.0, 144.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-32",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "change the slider to alter the brightness of the LED",
				"linecount" : 3,
				"patching_rect" : [ 90.0, 235.0, 117.0, 48.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-7",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "number",
				"patching_rect" : [ 215.0, 385.0, 50.0, 19.0 ],
				"numoutlets" : 2,
				"fontsize" : 10.0,
				"outlettype" : [ "int", "bang" ],
				"id" : "obj-6",
				"fontname" : "Verdana",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "slider",
				"patching_rect" : [ 215.0, 235.0, 20.0, 140.0 ],
				"numoutlets" : 1,
				"outlettype" : [ "" ],
				"bgcolor" : [ 0.94902, 0.94902, 0.94902, 0.0 ],
				"id" : "obj-1",
				"size" : 256.0,
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "select 0 1",
				"patching_rect" : [ 342.0, 305.0, 62.0, 20.0 ],
				"numoutlets" : 3,
				"fontsize" : 12.0,
				"outlettype" : [ "bang", "bang", "" ],
				"id" : "obj-30",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "click here to close the serial port",
				"patching_rect" : [ 390.0, 396.0, 206.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-26",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "click here to open the serial port",
				"patching_rect" : [ 415.0, 370.0, 206.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-27",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "close",
				"patching_rect" : [ 342.0, 396.0, 39.0, 18.0 ],
				"numoutlets" : 1,
				"fontsize" : 12.0,
				"outlettype" : [ "" ],
				"id" : "obj-21",
				"fontname" : "Arial",
				"numinlets" : 2
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "port a",
				"patching_rect" : [ 364.0, 370.0, 41.0, 18.0 ],
				"numoutlets" : 1,
				"fontsize" : 12.0,
				"outlettype" : [ "" ],
				"id" : "obj-19",
				"fontname" : "Arial",
				"numinlets" : 2
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "Click here to get a list of serial ports",
				"patching_rect" : [ 435.0, 344.0, 207.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-2",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "toggle",
				"patching_rect" : [ 342.0, 268.0, 15.0, 15.0 ],
				"numoutlets" : 1,
				"outlettype" : [ "int" ],
				"id" : "obj-11",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "message",
				"text" : "print",
				"patching_rect" : [ 384.0, 344.0, 36.0, 18.0 ],
				"numoutlets" : 1,
				"fontsize" : 12.0,
				"outlettype" : [ "" ],
				"id" : "obj-13",
				"fontname" : "Arial",
				"numinlets" : 2
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "newobj",
				"text" : "serial a 9600",
				"patching_rect" : [ 259.0, 420.0, 84.0, 20.0 ],
				"numoutlets" : 2,
				"fontsize" : 12.0,
				"outlettype" : [ "int", "" ],
				"id" : "obj-14",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "comment",
				"text" : "Click to start",
				"patching_rect" : [ 369.0, 268.0, 117.0, 20.0 ],
				"numoutlets" : 0,
				"fontsize" : 12.0,
				"id" : "obj-17",
				"fontname" : "Arial",
				"numinlets" : 1
			}

		}
, 		{
			"box" : 			{
				"maxclass" : "panel",
				"patching_rect" : [ 215.0, 235.0, 21.0, 139.0 ],
				"numoutlets" : 0,
				"mode" : 1,
				"grad1" : [ 1.0, 1.0, 1.0, 1.0 ],
				"id" : "obj-8",
				"grad2" : [ 0.509804, 0.509804, 0.509804, 1.0 ],
				"numinlets" : 1,
				"angle" : 270.0
			}

		}
 ],
	"lines" : [ 		{
			"patchline" : 			{
				"source" : [ "obj-11", 0 ],
				"destination" : [ "obj-30", 0 ],
				"hidden" : 0,
				"midpoints" : [ 351.0, 296.0, 351.5, 296.0 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-30", 1 ],
				"destination" : [ "obj-19", 0 ],
				"hidden" : 0,
				"midpoints" : [  ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-30", 0 ],
				"destination" : [ "obj-21", 0 ],
				"hidden" : 0,
				"midpoints" : [  ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-21", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 351.5, 416.5, 268.5, 416.5 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-19", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 373.5, 393.5, 268.5, 393.5 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-13", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 393.5, 365.5, 268.5, 365.5 ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-1", 0 ],
				"destination" : [ "obj-6", 0 ],
				"hidden" : 0,
				"midpoints" : [  ]
			}

		}
, 		{
			"patchline" : 			{
				"source" : [ "obj-6", 0 ],
				"destination" : [ "obj-14", 0 ],
				"hidden" : 0,
				"midpoints" : [ 224.5, 411.5, 268.5, 411.5 ]
			}

		}
 ]
}

April 15, 2009, at 10:52 PM by Tom Igoe -
Added lines 7-8:

You can send bytes to the Arduino from any software that can access the computer serial port. Examples for Processing and Max/MSP version 5 are shown below.

Changed lines 16-17 from:

int ledPin = 9;

to:

/*

  Dimmer

 Demonstrates the sending data from the computer to the Arduino board,
 in this case to control the brightness of an LED.  The data is sent
 in individual bytes, each of which ranges from 0 to 255.  Arduino
 reads these bytes and uses them to set the brightness of the LED.

 The circuit:
 LED attached from digital pin 9 to ground.
 Serial connection to Processing, Max/MSP, or another serial application

 created 2006
 by David A. Mellis
 modified 14 Apr 2009
 by Tom Igoe and Scott Fitzgerald

 http://www.arduino.cc/en/Tutorial/Dimmer
 */

  1. define ledPin 9 // the pin that the LED is attached to
Changed line 40 from:
  // begin the serial communication
to:
  // initialize the serial communication:
Added line 42:
  // initialize the ledPin as an output:
Changed lines 46-50 from:

void loop() {

  byte val;

  // check if data has been sent from the computer
to:

void loop() {

  byte brightness;

  // check if data has been sent from the computer:
Changed lines 51-54 from:
    // read the most recent byte (which will be from 0 to 255)
    val = Serial.read();
    // set the brightness of the LED
    analogWrite(ledPin, val);
to:
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
Added line 57:
Added lines 62-63:

Run the following sketch in Processing. It will send bytes out the serial port to the Arduino to dim the LED.

Deleted line 68:
Changed lines 71-72 from:

void setup() {

to:

void setup() {

Changed line 73 from:
to:
Changed line 76 from:
to:
Changed line 83 from:
to:
Changed lines 89-90 from:

void draw() {

to:

void draw() {

Changed line 95 from:
to:
Changed lines 100-108 from:

@]

to:

@]

Output

Max code

April 11, 2007, at 05:36 PM by David A. Mellis -
Added lines 1-78:

Examples > Communication

Dimmer

Demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of an LED. The data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the brightness of the LED.

Circuit

An LED connected to pin 9 (with appropriate resistor).

Code

int ledPin = 9;

void setup()
{
  // begin the serial communication
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  byte val;

  // check if data has been sent from the computer
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255)
    val = Serial.read();
    // set the brightness of the LED
    analogWrite(ledPin, val);
  }
}

Processing Code

// Dimmer - sends bytes over a serial port
// by David A. Mellis

import processing.serial.*;

Serial port;

void setup()
{
  size(256, 150);

  println("Available serial ports:");
  println(Serial.list());

  // Uses the first port in this list (number 0).  Change this to
  // select the port corresponding to your Arduino board.  The last
  // parameter (e.g. 9600) is the speed of the communication.  It
  // has to correspond to the value passed to Serial.begin() in your
  // Arduino sketch.
  port = new Serial(this, Serial.list()[0], 9600);  

  // If you know the name of the port used by the Arduino board, you
  // can specify it directly like this.
  //port = new Serial(this, "COM1", 9600);
}

void draw()
{
  // draw a gradient from black to white
  for (int i = 0; i < 256; i++) {
    stroke(i);
    line(i, 0, i, 150);
  }

  // write the current X-position of the mouse to the serial port as
  // a single byte
  port.write(mouseX);
}

Share