Tutorial.VirtualColorMixer History

Hide minor edits - Show changes to markup

June 05, 2010, at 09:05 PM by Equipo Traduccion -
Changed line 62 from:
  // List all the available serial ports
to:
  // Lista todos los puertos serie disponibles
Changed lines 64-66 from:
  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
to:
  // Doy por hecho que el primer puerto serie de la lista de mi mac
  // es siempre mi Arduino, por tanto abro Serial.list()[0].
  // Abre el puerto que estés usando.
Changed line 68 from:
  // don't generate a serialEvent() unless you get a newline character:
to:
  // no genera un serialEvent() a menos que se obtenga un caracter de nueva línea:
Changed line 73 from:
  // set the background color with the color values:
to:
  // establece el color de fondo con los valores de los colores:
Changed line 78 from:
  // get the ASCII string:
to:
  // recoge la cadena ASCII:
Changed line 82 from:
    // trim off any whitespace:
to:
    // elimina cualquier espacio en blanco:
Changed lines 84-85 from:
    // split the string on the commas and convert the 
    // resulting substrings into an integer array:
to:
    // divide la cadena por las comas y convierte las 
    // subcadenas resultantes en un array de enteros:
Changed lines 87-89 from:
    // if the array has at least three elements, you know
    // you got the whole thing.  Put the numbers in the
    // color variables:
to:
    // si la matriz tiene al menos tres elementos, ya sabes 
    // que los tienes todos. Ponga los números de las 
    // variables de los colores:
Changed lines 101-104 from:

Output

As you change the value of the analog sensors, the background color will change:

to:

Salida

A medida que cambian los valores de los sensores analógicos el color de fondo cambiará:

Changed lines 107-110 from:

Max Code

The max patch looks like this. The text of the patch is linked behind the image.

to:

Código de Max

El programa (patch) max se verá como este. El texto del código está enlazaco en la imagen.

June 05, 2010, at 08:51 PM by Equipo Traduccion -
Changed lines 34-35 from:

Processing Code

to:

Código de Processing

Changed lines 38-43 from:

// Color Mixer

// This example takes in a serial string of comma-separated values // from 0 to 1023, maps them to the range 0 to 255, and uses them // to change the background color

to:

// Mezclador de Colores

// Este ejemplo toma una serie de valores separados por comas // desde 0 a 1023, lo mapea en el rango de 0 a 255, y los usa para // cambiar el color de fondo

Changed lines 48-50 from:

// This example code is in the public domain.

to:

// Este código de ejemplo es de dominio público.

Changed lines 53-56 from:

float redValue = 0; // red value float greenValue = 0; // green value float blueValue = 0; // blue value

to:

float redValue = 0; // valor rojo float greenValue = 0; // valor verde float blueValue = 0; // valor azul

June 05, 2010, at 08:47 PM by Equipo Traduccion -
Changed lines 1-13 from:

Examples > Communication

Virtual Color Mixer

Demonstrates one technique for sending multiple values from the Arduino board to the computer. In this case, the readings from three potentiometers are used to set the red, green, and blue components of the background color of a Processing sketch.

Circuit

Analog sensors connected to analog input pins 0, 1, and 2.

This circuit uses three voltage divider sub-circuits to generate analog voltages from the force-sensing resistors. a voltage divider has two resistors in series, dividing the voltage proportionally to their values.

Click on the image to enlarge

to:

Ejemplos > Comunicaciones

Mezclador de Color Virtual

Demuestra una técnica para el envío de varios valores de la placa Arduino al ordenador. En este caso, las lecturas de tres potenciómetros se utilizan para establecer los componentes rojo, verde y azul del color de fondo de un programa en Processing.

Circuito

Conectados sensores analógicos a las entradas analógicas 0, 1 y 2.

Este circuito utiliza tres sub-circuitos divisores de tensión para generar voltajes desde las resistencias de los sensores de fuerza. Un divisor de voltaje tiene dos resistencias en serie, dividiendo la tensión de forma proporcional a sus valores.

Haz click en la imagen para ampliarla

Changed lines 16-21 from:

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

Schematic

Click on the image to enlarge

to:

imagen desarrollada usando Fritzing. Para más circuitos de ejemplo, visita la página del proyecto Fritzing

Esquema

Haz click en la imagen para ampliarla

Changed line 26 from:

Code

to:

Código

February 23, 2010, at 11:34 PM by Tom Igoe -
Changed lines 29-44 from:
 /*
   This example reads three analog sensors (potentiometers are easiest)
  and sends their values serially. The Processing and Max/MSP programs at the bottom
  take those three values and use them to change the background color of the screen.
  
  The circuit:
  * potentiometers attached to analog inputs 0, 1, and 2
  
  http://www.arduino.cc/en/Tutorial/VirtualColorMixer
  
  created 2 Dec 2006
  by David A. Mellis
  modified 14 Apr 2009 
  by Tom Igoe and Scott Fitzgerald
  
  */
to:
Deleted lines 30-47:
 const int redPin = 0;		// sensor to control red color
 const int greenPin = 1;		// sensor to control green color
 const int bluePin = 2;		// sensor to control blue color

 void setup()
 {
   Serial.begin(9600);
 }

 void loop()
 {
   Serial.print(analogRead(redPin));
   Serial.print(",");
   Serial.print(analogRead(greenPin));
   Serial.print(",");
   Serial.println(analogRead(bluePin));
 }
Added line 33:
Changed lines 48-49 from:
to:

// This example code is in the public domain.

August 27, 2009, at 08:56 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:38 PM by Tom Igoe -
Changed lines 25-65 from:
to:
Changed lines 67-89 from:

const int redPin = 0; const int greenPin = 1; const int bluePin = 2;

void setup() {

  Serial.begin(9600);

}

void loop() {

  Serial.print(analogRead(redPin));
  Serial.print(",");
  Serial.print(analogRead(greenPin));
  Serial.print(",");
  Serial.println(analogRead(bluePin));

} @]

Processing Code

[@

to:
June 25, 2009, at 11:25 PM by Tom Igoe -
Changed lines 14-16 from:

to:

June 25, 2009, at 11:01 PM by Tom Igoe -
Changed lines 27-30 from:
  1. define redPin 0
  2. define greenPin 1
  3. define bluePin 2
to:

const int redPin = 0; const int greenPin = 1; const int bluePin = 2;

June 25, 2009, at 11:00 PM by Tom Igoe -
Changed line 13 from:

Click on the image to enlarge.

to:

Click on the image to enlarge

Changed lines 17-23 from:
to:

Schematic

Click on the image to enlarge

May 04, 2009, at 05:17 PM by Tom Igoe -
Changed lines 14-17 from:

to:

May 04, 2009, at 05:17 PM by Tom Igoe -
Changed lines 14-17 from:

to:

May 04, 2009, at 05:13 PM by Tom Igoe -
Changed lines 14-17 from:

to:

May 04, 2009, at 05:12 PM by Tom Igoe -
Added lines 11-12:

This circuit uses three voltage divider sub-circuits to generate analog voltages from the force-sensing resistors. a voltage divider has two resistors in series, dividing the voltage proportionally to their values.

Changed lines 14-17 from:

to:

April 16, 2009, at 07:46 PM by Tom Igoe -
Changed lines 12-15 from:

to:

April 16, 2009, at 01:22 PM by Tom Igoe -
Changed lines 12-15 from:

to:

April 16, 2009, at 01:20 PM by Tom Igoe -
April 16, 2009, at 01:20 PM by Tom Igoe -
Changed lines 12-15 from:

to:

April 16, 2009, at 01:19 PM by Tom Igoe -
Changed lines 12-15 from:

to:

April 16, 2009, at 01:19 PM by Tom Igoe -
April 16, 2009, at 01:18 PM by Tom Igoe -
Deleted lines 8-9:
Changed lines 11-15 from:
to:

Click on the image to enlarge.

April 16, 2009, at 01:17 PM by Tom Igoe -
Changed lines 9-10 from:
to:
April 16, 2009, at 12:29 AM by Tom Igoe -
Changed lines 9-10 from:

Potentiometers connected to analog input pins 0, 1, and 2.

to:

Analog sensors connected to analog input pins 0, 1, and 2.

Changed lines 17-20 from:

int redPin = 0; int greenPin = 1; int bluePin = 2;

to:
  1. define redPin 0
  2. define greenPin 1
  3. define bluePin 2
Changed lines 28-32 from:
  Serial.print("R");
  Serial.println(analogRead(redPin));
  Serial.print("G");
  Serial.println(analogRead(greenPin));
  Serial.print("B");
to:
  Serial.print(analogRead(redPin));
  Serial.print(",");
  Serial.print(analogRead(greenPin));
  Serial.print(",");
Deleted line 32:
  delay(100);
Changed lines 39-51 from:

/**

 * Color Mixer
 * by David A. Mellis
 *
 * Created 2 December 2006
 *
 * based on Analog In 
 * by <a href="http://itp.jtnimoy.com">Josh Nimoy</a>. 
 * 
 * Created 8 February 2003
 * Updated 2 April 2005
 */
to:

// Color Mixer

// This example takes in a serial string of comma-separated values // from 0 to 1023, maps them to the range 0 to 255, and uses them // to change the background color

// Created 2 Dec 2006 // by David A. Mellis // modifed 14 Apr 2009 // by Tom Igoe

Changed lines 54-61 from:

String buff = ""; int rval = 0, gval = 0, bval = 0; int NEWLINE = 10;

Serial port;

void setup() {

to:

float redValue = 0; // red value float greenValue = 0; // green value float blueValue = 0; // blue value

Serial myPort;

void setup() {

Changed lines 63-64 from:
  // Print a list in case COM1 doesn't work out
  println("Available serial ports:");
to:
  // List all the available serial ports
Changed lines 65-68 from:
  //port = new Serial(this, "COM1", 9600);
  // Uses the first available port
  port = new Serial(this, Serial.list()[0], 9600);
to:
  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[0], 9600);
  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');
Changed lines 73-78 from:

void draw() {

  while (port.available() > 0) {
    serialEvent(port.read());
  }
  background(rval, gval, bval);
to:

void draw() {

  // set the background color with the color values:
  background(redValue, greenValue, blueValue);
Changed lines 78-101 from:

void serialEvent(int serial) {

  // If the variable "serial" is not equal to the value for 
  // a new line, add the value to the variable "buff". If the 
  // value "serial" is equal to the value for a new line,
  //  save the value of the buffer into the variable "val".
  if(serial != NEWLINE) { 
    buff += char(serial);
  } else {
    // The first character tells us which color this value is for
    char c = buff.charAt(0);
    // Remove it from the string
    buff = buff.substring(1);
    // Discard the carriage return at the end of the buffer
    buff = buff.substring(0, buff.length()-1);
    // Parse the String into an integer
    if (c == 'R')
      rval = Integer.parseInt(buff);
    else if (c == 'G')
      gval = Integer.parseInt(buff);
    else if (c == 'B')
      bval = Integer.parseInt(buff);
    // Clear the value of "buff"
    buff = "";
to:

void serialEvent(Serial myPort) {

  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // split the string on the commas and convert the 
    // resulting substrings into an integer array:
    float[] colors = float(split(inString, ","));
    // if the array has at least three elements, you know
    // you got the whole thing.  Put the numbers in the
    // color variables:
    if (colors.length >=3) {
      // map them to the range 0-255:
      redValue = map(colors[0], 0, 1023, 0, 255);
      greenValue = map(colors[1], 0, 1023, 0, 255);
      blueValue = map(colors[2], 0, 1023, 0, 255);
    }
Changed lines 99-112 from:

@]

to:

@]

Output

As you change the value of the analog sensors, the background color will change:

Max Code

The max patch looks like this. The text of the patch is linked behind the image.

March 26, 2007, at 02:39 PM by David A. Mellis -
Added lines 1-12:

Examples > Communication

Virtual Color Mixer

Demonstrates one technique for sending multiple values from the Arduino board to the computer. In this case, the readings from three potentiometers are used to set the red, green, and blue components of the background color of a Processing sketch.

Circuit

Potentiometers connected to analog input pins 0, 1, and 2.

Code

Changed lines 33-37 from:
to:

@]

Processing Code

[@

Deleted line 50:

/*

Deleted line 105:
  • /
January 14, 2007, at 03:30 PM by David A. Mellis -
Added lines 1-92:
int redPin = 0;
int greenPin = 1;
int bluePin = 2;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print("R");
  Serial.println(analogRead(redPin));
  Serial.print("G");
  Serial.println(analogRead(greenPin));
  Serial.print("B");
  Serial.println(analogRead(bluePin));
  delay(100);
}

/**
 * Color Mixer
 * by David A. Mellis
 *
 * Created 2 December 2006
 *
 * based on Analog In 
 * by <a href="http://itp.jtnimoy.com">Josh Nimoy</a>. 
 * 
 * Created 8 February 2003
 * Updated 2 April 2005
 */

/*
import processing.serial.*;

String buff = "";
int rval = 0, gval = 0, bval = 0;
int NEWLINE = 10;

Serial port;

void setup()
{
  size(200, 200);

  // Print a list in case COM1 doesn't work out
  println("Available serial ports:");
  println(Serial.list());

  //port = new Serial(this, "COM1", 9600);
  // Uses the first available port
  port = new Serial(this, Serial.list()[0], 9600);
}

void draw()
{
  while (port.available() > 0) {
    serialEvent(port.read());
  }
  background(rval, gval, bval);
}

void serialEvent(int serial) 
{ 
  // If the variable "serial" is not equal to the value for 
  // a new line, add the value to the variable "buff". If the 
  // value "serial" is equal to the value for a new line,
  //  save the value of the buffer into the variable "val".
  if(serial != NEWLINE) { 
    buff += char(serial);
  } else {
    // The first character tells us which color this value is for
    char c = buff.charAt(0);
    // Remove it from the string
    buff = buff.substring(1);
    // Discard the carriage return at the end of the buffer
    buff = buff.substring(0, buff.length()-1);
    // Parse the String into an integer
    if (c == 'R')
      rval = Integer.parseInt(buff);
    else if (c == 'G')
      gval = Integer.parseInt(buff);
    else if (c == 'B')
      bval = Integer.parseInt(buff);
    // Clear the value of "buff"
    buff = "";
  }
}
*/

Share