Color picker–Processing
Here is another project with High Power RGB LED Shield and Arduino.
This is rather simple way of communicated with the computer and can be useful for initial testing and color matching.
What you need
- Arduino (any version)
- High Power RGB LED shield
- RGB LED
Arduino Libraries
- HPRGB Library : powering High Power RGB LED Shield
Processing Application
Rapplogic made nice color picker application with Processing. You don’t need to modify any code in here. If you have trouble running the application, make sure to put path and changing com port in ledcolorpicker.cmd (windows) or ledcolorpicker.sh (mac osx and linux)
1: # this script requires java 1.5 in your path
2: path C:\Program Files\Java\jre6\bin
3: # replace the last argument with the COM port of your Arduino
4: java -classpath lib\colorpicker.jar;lib\log4j.jar;lib\RXTXcomm.jar;ledcolorpicker.jar -Djava.library.path=. com.rapplogic.ledcolorpicker.LedColorPicker COM6
Circuit & Setup
No special circuit here. Just setup Arduino + HP RGB Shield + LED, then connect to a computer.
Arduino Code
The couple of lines of arduino code has been modified to make it work with HP RGB Shield.
It is essentially just changing “analogWrite” to “goToRGB”. For version 1 shield users, change shield library include to “#include <HPRGB.h>”.
1: #include <Wire.h>
2: #include <HPRGB2.h>
3:
4: HPRGB ledShield; // default mcp4728 id(0) and default PCA9685 id(0)
5:
6: // Indicates what color we are reading next; 0 = red, 1 = green, 2 = blue
7: int pos = 0;
8:
9: // red PWM value
10: int red = 0;
11: // green PWM value
12: int green = 0;
13: // blue PWM value
14: int blue = 0;
15:
16: // indicates if next byte should be unescaped
17: boolean escape = false;
18:
19: void setup() {
20: Serial.begin(9600);
21: ledShield.begin();
22: }
23:
24: void loop () {
25:
26: while (Serial.available()) {
27: int rgb = Serial.read();
28:
29: if (rgb == 1) {
30: // end of RGB sequence byte
31: // reset pos
32: pos = 0;
33:
34: // process this color
35: ledShield.goToRGB(red,green,blue);
36:
37: // Send ACK byte so Java app can send the next color
38: Serial.print("k");
39: Serial.flush();
40:
41: // get next byte
42: continue;
43: } else if (rgb == 2) {
44: // escape byte
45: escape = true;
46: // discard byte and read next byte
47: continue;
48: }
49:
50: if (escape) {
51: // unescape byte
52: rgb = 0x20 ^ rgb;
53: // reset escape
54: escape = false;
55: }
56:
57: switch (pos++) {
58: case 0:
59: red = rgb;
60: break;
61: case 1:
62: green = rgb;
63: break;
64: case 2:
65: blue = rgb;
66: break;
67: }
68: }
69: }
Video
Demonstration of setup and code
- Will be added soon.
After some initial head scratching I got this to work on my iMac.
S W E E T!
There is one comment the rapplocig site that a -d32 flag needs to be added on OSX machines because the serial library is compiled against 32 bit. I just was not sure where! It is a java parameter so it goes right after the “java” in the last line of the script.