Description:
Launch a mouse-based color picker in Processing. Collected color data is sent to the 3 LEDs.
I can't figure out how to integrate blue well into the color picker. Any advice?
Components:
• 3x LEDs (R, G & B)
• 3x 220Ohm resistor
Arduino Code:
int rPin = 11;
int gPin = 10;
int bPin = 9;
int serialColors[3];
int serialCount = 0;
char val;
int rByte;
int gByte;
int bByte;
void setup()
{
Serial.begin(9600);
pinMode(rPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
}
void loop()
{
if (Serial.available() > 0) {
serialColors[serialCount] = Serial.read();
serialCount++;
if (serialCount > 2) {
rByte = serialColors[0];
gByte = serialColors[1];
bByte = serialColors[2];
Serial.println(rByte);
analogWrite(rPin, rByte);
analogWrite(gPin, gByte);
analogWrite(bPin, bByte);
serialCount = 0;
}
}
}
Processing Code:
import processing.serial.*;
Serial port;
float xmag, ymag = 0;
float newXmag, newYmag = 0;
void setup()
{
size(255, 255);
noStroke();
colorMode(HSB, 255);
frameRate(10);
for(int i=0; i<255; i++) {
for(int j=0; j<255; j++) {
stroke(i, j, 255);
point(i, j);
}
}
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}
float getRed()
{
return red(get(mouseX,mouseY));
}
float getGreen()
{
return (green(get(mouseX,mouseY)));
}
float getBlue()
{
return (blue(get(mouseX,mouseY)));
}
void draw()
{
int r = 0;
int g = 0;
int b = 0;
r = int(getRed());
g = int(getGreen());
b = int(getBlue());
// println("r =" + r);
// println("g =" + g);
// println("b =" + b);
port.write(r);
port.write(g);
port.write(b);
}
Photo:
En route!
Comments
GSI Comments
Great idea! I like the interaction between the "standard" color picker on the screen and the unique physical output on the Arduino. Unforunately, we can't see what you did because there aren't any photos. :( Could you please post them?