Virtual Color Remixer
Arduino + Processing
Motivações
Construção de novas ferramentas interativas para manipulação de imagens em tempo real.
Funções
Altera os valores RGB e o background de imagens usando potenciômetros e ldr.
Materiais
- Arduino
- Protoboard
- 3 Potenciômetros
- LDRs
- Resistores
- Fios
Softwares
Processing -> Plataforma open-source para prototipagem de interfaces audio-visuais interativas.
Arduino -> Plataforma open-source baseada em um circuito de entradas/saídas simples
Montagem
Potenciômetros
Solde os 3 potenciômetros e ligue os fios nas seguintes posições:
Direita: 5 voltz
Esquerda: gnd
Meio: Analog 0, 1 e 2.
Veja na foto acima como fazer pra fazer a ligação na protoboard, ou veja esse
link.
LDR
Coloque o LDR na protoboard e usando um resistor faça um circuito e coloque sua saída na Analog 3.
Arduino code:
int redPin = 0;
int greenPin = 1;
int bluePin = 2;
int ldrPin = 3;
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));
Serial.print("L");
Serial.println(analogRead(ldrPin));
delay(100);
}
Processing Code
import processing.serial.*;
String buff = "";
int rval = 0, gval = 0, bval = 0, lval=0;
int NEWLINE = 10;
Serial port;
void setup()
{
size(500, 500);
noStroke();
smooth();
// 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); // inverta a ultima chave do zero.(so pra nao da rolo no wiki)
}
void draw()
{
while (port.available() > 0) {
serialEvent(port.read());
}
background(random(lval*2), random(lval), random(lval));
for(int i=0; i<height; i+=20) {
// println("o valor de i eh "+i);
fill(rval,gval,bval);
rect(0,i,width,10);
fill(random(0,100));
rect(0,i,width,10);
fill(random(rval), random(gval), random(bval));
rect(i,0,10,height);
}
}
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);
//println("rval "+rval);
else if (c == 'G')
gval = Integer.parseInt(buff);
//println("gval "+gval);
else if (c == 'B')
bval = Integer.parseInt(buff);
else if (c == 'L')
lval = Integer.parseInt(buff);
//println("bval "+bval);
// Clear the value of "buff"
buff = "";
}
}
Exemplo
Este exemplo fica alterando as cores R.G.B através do valor dos potenciômetros e o LDR fica alterando aleatoriamente o background. Tente experimentar criar outras coisas com essas variáveis recebidas do Arduino..
Custos
O custo médio dessa ferramenta foi:
Materiais (fios, potenciometros, ldr, protoboard) - R$23,00
Arduino - $34,00
E o pesquisador, cobra quanto?