105
edits
Changes
no edit summary
analogWrite(PIN_GREEN, g);
analogWrite(PIN_BLUE, b);
}
===Code (Processing)===
//This code belongs in Processing.
//It creates a color wheel that allows you to click on it.
//The RGB LED will respond to the color you click on.
import processing.serial.*;
Serial port;
void setup() {
size(100, 150); //window size
noStroke();
// Background
colorMode(HSB, 100);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
stroke(i, j, 100);
point(i, j);
}
}
// Select port
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
}
void draw()
{
// Only to enable the method mouseDragged
}
//click mouse to select color
void mouseClicked()
{
processColor();
}
//click and drag mouse to change color of light
void mouseDragged()
{
processColor();
}
void processColor()
{
color c = get(mouseX, mouseY);
noStroke();
fill(c);
rect(0, 100, 100, 50);
sendColorToSerial(c);
}
void sendColorToSerial(color colour)
{
// Get HEX
String hexColor = hex(colour, 6);
// Convert HEC to Number
long numColor = unhex(hexColor);
// Send color number to serial port
port.write("^" + numColor + "$");
}