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;
void setup()
{
size(255, 255);
noStroke();
frameRate(10);
noStroke();
colorMode(RGB, 255);
for(int i=0; i<255; i++) {
for(int j=0; j<255; j++) {
stroke(i, j, 100);
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!