Tutorial.LEDColorMixerWith3Potentiometers History

Hide minor edits - Show changes to markup

June 10, 2010, at 12:14 AM by Equipo Traduccion -
Changed lines 3-20 from:
  • "Coffee-cup" Color Mixer:
  • Code for mixing and reporting PWM-mediated color
  • Assumes Arduino 0004 or higher, as it uses Serial.begin()-style communication
  • Control 3 LEDs with 3 potentiometers
  • If the LEDs are different colors, and are directed at diffusing surface (stuck in a
  • a Ping-Pong ball, or placed in a paper coffee cup with a cut-out bottom and
  • a white plastic lid), the colors will mix together.
  • When you mix a color you like, stop adjusting the pots.
  • The mix values that create that color will be reported via serial out.
  • Standard colors for light mixing are Red, Green, and Blue, though you can mix
  • with any three colors; Red + Blue + White would let you mix shades of red,
  • blue, and purple (though no yellow, orange, green, or blue-green.)
  • Put 220 Ohm resistors in line with pots, to prevent circuit from
  • grounding out when the pots are at zero
to:
  • Mezclador de colores "taza de café":
  • Código para mezclar un color y presentarlo mediante PWM.
  • Para versiones de Arduino 0004 o superiores, se utilizan funciones de comunicación serie para el depurado.
  • Control de 3 LEDs con 3 potenciómetros.
  • Si los LEDs son de diferentes colores y se dirigen hacia una superficie difusora los colores se mezclarán.
  • Cuando encuentres el color que buscas deja de ajustar los potenciómetros.
  • Los valores que han creado el color serán enviados por el puerto serie.
  • Los colores estándar para mezclar luces son el rojo, el verde y el azul, pero puedes
  • probar con otros tres colores; rojo + azul + blanco te permitirán mezclar gamas de rojo.
  • Utiliza resistencias de 220 Ohm en serie con los potenciómetros para prevenir la puesta a tierra del
  • circuito cuando los potenciómetros estén a cero.
Changed lines 16-18 from:

// Analog pin settings int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2 int bIn = 1; // (Connect power to 5V and ground to analog ground)

to:

// Establecemos los pines analógicos int aIn = 0; // Potenciómetros conectados a los pines analógicos 0, 1 y 2 int bIn = 1; // (Conectar alimentación a 5V y masa a GND)

Changed lines 21-23 from:

// Digital pin settings int aOut = 9; // LEDs connected to digital pins 9, 10 and 11 int bOut = 10; // (Connect cathodes to digital ground)

to:

// Establecemos los pines digitales int aOut = 9; // LEDs conectados a los pines digitales 9, 10 y 11 int bOut = 10; // (Conectar los cátodos a GND)

Changed lines 26-27 from:

// Values int aVal = 0; // Variables to store the input from the potentiometers

to:

// Valores int aVal = 0; // Variables para almacenar las entradas de los potenciómetros

Changed lines 31-35 from:

// Variables for comparing values between loops int i = 0; // Loop counter int wait = (1000); // Delay between most recent pot adjustment and output

int checkSum = 0; // Aggregate pot values

to:

// Variables para comparar valores entre ciclos int i = 0; // contador de ciclo int wait = (1000); // retardo entre el mas reciente ajuste de potenciómetro y salida

int checkSum = 0; // sumar al valor del potenciómetro

Changed lines 37-42 from:

int sens = 3; // Sensitivity theshold, to prevent small changes in

                      // pot values from triggering false reporting

// FLAGS int PRINT = 1; // Set to 1 to output values int DEBUG = 1; // Set to 1 to turn on debugging output

to:

int sens = 3; // umbral de sensivilidad, para prevenir pequeños cambios en

                      // los valores de los potenciómetros debidos al ruido

// BANDERAS int PRINT = 1; // puesto a 1 para dar salida a los valores int DEBUG = 1; // puesto a 1 para conectar la salida de depurado

Changed line 45 from:
  pinMode(aOut, OUTPUT);   // sets the digital pins as output
to:
  pinMode(aOut, OUTPUT);   // establece los pines digitales como salidas
Changed line 48 from:
  Serial.begin(9600);     // Open serial communication for reporting
to:
  Serial.begin(9600);     // inicializa la comunicación serie
Changed lines 53-55 from:
  i += 1; // Count loop

  aVal = analogRead(aIn) / 4;  // read input pins, convert to 0-255 scale
to:
  i += 1; // contador de ciclos

  aVal = analogRead(aIn) / 4;  // lee los pines de entrada y escala 0-255
Changed line 59 from:
  analogWrite(aOut, aVal);    // Send new values to LEDs
to:
  analogWrite(aOut, aVal);    // envía los nuevos valores a los LEDs
Changed line 63 from:
  if (i % wait == 0)                // If enough time has passed...
to:
  if (i % wait == 0)                // si ha pasado suficiente tiempo...
Changed lines 65-67 from:
    checkSum = aVal+bVal+cVal;      // ...add up the 3 values.
    if ( abs(checkSum - prevCheckSum) > sens )   // If old and new values differ 
                                                  // above sensitivity threshold
to:
    checkSum = aVal+bVal+cVal;      // ...suma los tres valores.
    if ( abs(checkSum - prevCheckSum) > sens )   // Si los viejos y los nuevos valores son diferentes 
                                                  // por encima del umbral de sensivilidad
Changed line 69 from:
      if (PRINT)                    // ...and if the PRINT flag is set...
to:
      if (PRINT)                    // ...y si la bandera PRINT está establecida...
Changed line 71 from:
        Serial.print("A: ");        // ...then print the values.
to:
        Serial.print("A: ");        // ...imprime los valores.
Changed line 84 from:
      PRINT = 1;  // Re-set the flag   
to:
      PRINT = 1;  // resetea la bandera   
Changed line 86 from:
    prevCheckSum = checkSum;  // Update the values
to:
    prevCheckSum = checkSum;  // actualiza los valores
Changed line 88 from:
    if (DEBUG)   // If we want debugging output as well...
to:
    if (DEBUG)   // si queremos salida de depurado...
September 07, 2006, at 02:57 PM by Clay Shirky - Fixed sensitivity bug
Changed lines 73-74 from:
    if ( abs(checkSum - prevCheckSum) <= sens )   // If old and new values are 
                                                  // within "sens" points...
to:
    if ( abs(checkSum - prevCheckSum) > sens )   // If old and new values differ 
                                                  // above sensitivity threshold
September 07, 2006, at 03:02 AM by Clay Shirky -
Changed line 74 from:
                                                  // within sens points...
to:
                                                  // within "sens" points...
September 07, 2006, at 03:00 AM by Clay Shirky -
Changed lines 8-10 from:
  • If the LEDs are different colors, and are directed at a diffusing surface (stuck in a
  • Ping-Pong ball, or placed in a paper coffee cup with a cut-out bottom and a white plastic lid),
  • the colors will mix together.
to:
  • If the LEDs are different colors, and are directed at diffusing surface (stuck in a
  • a Ping-Pong ball, or placed in a paper coffee cup with a cut-out bottom and
  • a white plastic lid), the colors will mix together.
September 07, 2006, at 02:59 AM by Clay Shirky -
Changed lines 8-9 from:
  • If the LEDs are different colors, and are behind a diffusing surface (anything
  • from a Ping-Pong ball to a coffee cup with a cut-out bottom and a white plastic lid),
to:
  • If the LEDs are different colors, and are directed at a diffusing surface (stuck in a
  • Ping-Pong ball, or placed in a paper coffee cup with a cut-out bottom and a white plastic lid),
September 07, 2006, at 02:58 AM by Clay Shirky -
Changed line 1 from:

[=

to:
 [=
Added line 105:

=]

September 07, 2006, at 02:56 AM by Clay Shirky -
Added line 1:

[=

Changed line 3 from:
  • Espresso-cup Color Mixer:
to:
  • "Coffee-cup" Color Mixer:
Changed lines 9-10 from:
  • from a Ping-Pong ball to a coffee cup with a white plastic lid), the colors
  • will mix together.
to:
  • from a Ping-Pong ball to a coffee cup with a cut-out bottom and a white plastic lid),
  • the colors will mix together.
September 07, 2006, at 02:53 AM by Clay Shirky -
Added lines 1-103:

/*

  • Espresso-cup Color Mixer:
  • Code for mixing and reporting PWM-mediated color
  • Assumes Arduino 0004 or higher, as it uses Serial.begin()-style communication
  • Control 3 LEDs with 3 potentiometers
  • If the LEDs are different colors, and are behind a diffusing surface (anything
  • from a Ping-Pong ball to a coffee cup with a white plastic lid), the colors
  • will mix together.
  • When you mix a color you like, stop adjusting the pots.
  • The mix values that create that color will be reported via serial out.
  • Standard colors for light mixing are Red, Green, and Blue, though you can mix
  • with any three colors; Red + Blue + White would let you mix shades of red,
  • blue, and purple (though no yellow, orange, green, or blue-green.)
  • Put 220 Ohm resistors in line with pots, to prevent circuit from
  • grounding out when the pots are at zero
  • /

// Analog pin settings int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2 int bIn = 1; // (Connect power to 5V and ground to analog ground) int cIn = 2;

// Digital pin settings int aOut = 9; // LEDs connected to digital pins 9, 10 and 11 int bOut = 10; // (Connect cathodes to digital ground) int cOut = 11;

// Values int aVal = 0; // Variables to store the input from the potentiometers int bVal = 0; int cVal = 0;

// Variables for comparing values between loops int i = 0; // Loop counter int wait = (1000); // Delay between most recent pot adjustment and output

int checkSum = 0; // Aggregate pot values int prevCheckSum = 0; int sens = 3; // Sensitivity theshold, to prevent small changes in

                      // pot values from triggering false reporting

// FLAGS int PRINT = 1; // Set to 1 to output values int DEBUG = 1; // Set to 1 to turn on debugging output

void setup() {

  pinMode(aOut, OUTPUT);   // sets the digital pins as output
  pinMode(bOut, OUTPUT);   
  pinMode(cOut, OUTPUT); 
  Serial.begin(9600);     // Open serial communication for reporting

}

void loop() {

  i += 1; // Count loop

  aVal = analogRead(aIn) / 4;  // read input pins, convert to 0-255 scale
  bVal = analogRead(bIn) / 4; 
  cVal = analogRead(cIn) / 4;  

  analogWrite(aOut, aVal);    // Send new values to LEDs
  analogWrite(bOut, bVal);
  analogWrite(cOut, cVal);

  if (i % wait == 0)                // If enough time has passed...
  {    
    checkSum = aVal+bVal+cVal;      // ...add up the 3 values.
    if ( abs(checkSum - prevCheckSum) <= sens )   // If old and new values are 
                                                  // within sens points...
    {
      if (PRINT)                    // ...and if the PRINT flag is set...
      {
        Serial.print("A: ");        // ...then print the values.
        Serial.print(aVal);         
        Serial.print("\t"); 
        Serial.print("B: ");        
        Serial.print(bVal);
        Serial.print("\t");
        Serial.print("C: ");                
        Serial.println(cVal); 
        PRINT = 0;
      }
    }  
    else
    {
      PRINT = 1;  // Re-set the flag   
    } 
    prevCheckSum = checkSum;  // Update the values

    if (DEBUG)   // If we want debugging output as well...
    {
      Serial.print(checkSum);
      Serial.print("<=>");
      Serial.print(prevCheckSum);
      Serial.print("\tPrint: ");
      Serial.println(PRINT);
    }
  }

}

Share