The color selector is 3 linear pots that control the rgb values of a square in a window. The window also displays the rgb values. Kinda simple to make, I reused a lot of code from the etch-a-sketch sketch. I am working on my processing book, so my projects should get better.
The dot in the red pick, is me not being able to use a mouse properly, the lines on the text seem to be a problem with the font I picked.
/*
Color Selector
Takes 3 pots hooked up to analog 0,1,2 and uses them for the red green blue
values of a square.
Also displays the number for each color
*/
import processing.serial.*;
Serial myPort;
String inString; // Input string from serial port:
String letter;
int number;
String numberS;
int redNum, greenNum, blueNum;
int x = 300; //somewhere around 200 or 300
int y = 300;
int lf = 10;
PFont font;
void setup() {
size(x, y);
//you may have to change the serial port
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(lf);
background(0);
font = loadFont("aakar-medium-20.vlw"); //make your own font
}
void draw() {
background(0);
textFont(font);
fill(255, 0, 0);
text(redNum, 10,30);
fill(0, 255, 0);
text(greenNum, 70,30);
fill(0, 0, 255);
text(blueNum, 130,30);
fill(redNum, greenNum, blueNum);
rect(0,50,x,y);
}
void serialEvent(Serial p) {
inString = (myPort.readString());
letter = inString.substring(0, 1);
numberS = inString.substring(2);
numberS = trim(numberS);
number = Integer.parseInt(numberS); //I could have combined a bit of this, but this code is for learning
if(letter.equals("R") == true) {
redNum = number;
}
if(letter.equals("G") == true) {
greenNum = number;
}
if(letter.equals("B") == true) {
blueNum = number;
}
}
/*Arduino Code
int bluePin = 2; //analog pin for right hand knob
int greenPin = 1; //analog pin for left hand knob
int redPin = 0; //analog pin for center knob (width)
//Info for Serial Data
int id_1 = 'R';
int id_2 = 'G';
int id_3 = 'B';
int space = ' ';
void setup()
{
pinMode(redPin, INPUT);
pinMode(greenPin, INPUT);
pinMode(bluePin, INPUT);
Serial.begin(9600);
}
void loop()
{
int redNum = analogRead(redPin);
int greenNum = analogRead(greenPin);
int blueNum = analogRead(bluePin);
//the arduino will read from 0 to 1024 on teh analog pins, so we divide that by 4
redNum = redNum / 4;
greenNum = greenNum / 4;
blueNum = blueNum / 4;
printByte(id_1);
printByte(space);
printInteger(redNum); printByte(10);
printByte(id_2);
printByte(space);
printInteger(greenNum); printByte(10);
printByte(id_3);
printByte(space);
printInteger(blueNum); printByte(10);
delay(10);
}
*/