I’ve seen the concept art for “real world eyedroppers” several times. I haven’t noticed any of the products come to market though. It isn’t the technology stoping them, color sampling can be done a million ways. I picked one of the easiest ways and tossed something together pretty quickly.The method I chose is outlined in fantastic detail by [Fjordcarver] on instructibles. I took his project and used the Teensy2 instead of an arduino as well as seperate red, blue, and green LEDs since I had some lying around. He includes the schematic to do exactly that, so again, credit goes to him. [Fjordcarver] also made a processing sketch to display the colors. I wanted to actually use this, so I added a tiny feature where any keystroke will copy the hexidecimal color to the clipboard. This way I can just leave the “eyedropper” running and sample things whenever I want.








import processing.serial.*;import java.awt.datatransfer.*;import java.awt.Toolkit;String buff = "";int val = 0;int wRed, wGreen, wBlue;String col = "ffffff";ClipHelper cp = new ClipHelper();Serial port;void setup(){size(200,200); port = new Serial(this, "COM3", 9600); //remember to replace COM20 with the appropriate serial port on your computer}void draw(){ background(wRed,wGreen,wBlue); // check for serial, and process while (port.available() > 0) { serialEvent(port.read()); }}void keyPressed() { cp.copyString(""+col); }void serialEvent(int serial) {if(serial != '\n') { buff += char(serial); } else { int cRed = buff.indexOf("R"); int cGreen = buff.indexOf("G"); int cBlue = buff.indexOf("B");if(cRed >=0){ String val = buff.substring(cRed+3); wRed = Integer.parseInt(val.trim()); } if(cGreen >=0){ String val = buff.substring(cGreen+3); wGreen = Integer.parseInt(val.trim()); } if(cBlue >=0){ String val = buff.substring(cBlue+3); wBlue = Integer.parseInt(val.trim()); } col = hex(color(wRed, wGreen, wBlue), 6); buff = ""; }}// CLIPHELPER OBJECT CLASS:class ClipHelper { Clipboard clipboard; ClipHelper() { getClipboard(); } void getClipboard () { // this is our simple thread that grabs the clipboard Thread clipThread = new Thread() { public void run() { clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); } }; // start the thread as a daemon thread and wait for it to die if (clipboard == null) { try { clipThread.setDaemon(true); clipThread.start(); clipThread.join(); } catch (Exception e) {} } } void copyString (String data) { copyTransferableObject(new StringSelection(data)); } void copyTransferableObject (Transferable contents) { getClipboard(); clipboard.setContents(contents, null); } String pasteString () { String data = null; try { data = (String)pasteObject(DataFlavor.stringFlavor); } catch (Exception e) { System.err.println("Error getting String from clipboard: " + e); } return data; } Object pasteObject (DataFlavor flavor) throws UnsupportedFlavorException, IOException { Object obj = null; getClipboard(); Transferable content = clipboard.getContents(null); if (content != null) obj = content.getTransferData(flavor); return obj; }}
Filed under: arduino hacks, led hacks
