Skip to content

Instantly share code, notes, and snippets.

@cuervotronic
Forked from circuitsenses/rgb_kontrol
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuervotronic/8a6e64b3a3bfebba914d to your computer and use it in GitHub Desktop.
Save cuervotronic/8a6e64b3a3bfebba914d to your computer and use it in GitHub Desktop.
/**
* Subtractive Color Wheel
* by Ira Greenberg.
* Tint routine modified by Miles DeCoster
*
* The primaries are red, yellow, and blue. The secondaries are green,
* purple, and orange. The tertiaries are yellow-orange, red-orange,
* red-purple, blue-purple, blue-green, and yellow-green.
*
* Updated 10 January 2013.
* Arduino Serial Interface to RGB LED
* by Rishi F.
*
* Transmits RGB packet over serial port to Arduino UNO3 board
* to which a Piranha RGB LED is connected to the PWM pins. Find the
*
*
* Updated 5 December 2013
*/
import processing.serial.*;
int segs = 12;
int steps = 6;
float rotAdjust = TWO_PI / segs / 2;
float radius;
float segWidth;
float interval = TWO_PI / segs;
color bc = color(0, 0, 0);
byte [] rgbdata = new byte[64];
Serial ardPort;
void setup() {
size(200, 200);
background(0);
smooth();
ellipseMode(RADIUS);
noStroke();
// make the diameter 90% of the sketch area
radius = min(width, height) * 0.45;
segWidth = radius / steps;
println(Serial.list());
ardPort = new Serial(this, Serial.list()[1], 9600);
drawTintWheel();
}
void draw() {
// rectMode(CORNER);
bc = get(mouseX, mouseY);
//println("R G B = " + int(red(bc)) + " " + int(green(bc)) + " " + int(blue(bc)));
rgbdata[0] = (byte(int(red(bc))));
rgbdata[1] = (byte(int(green(bc))));
rgbdata[2] = (byte(int(blue(bc))));
// hold the last value when mouse moves away from the wheel
if ((rgbdata[0] ^ rgbdata[1] ^ rgbdata[2]) != 0) {
ardPort.write(rgbdata[0]);
ardPort.write(rgbdata[1]);
ardPort.write(rgbdata[2]);
}
}
void drawTintWheel() {
for (int j = 0; j < steps; j++) {
color[] cols = {
color(255, 255, ((255/(steps-1))*j)),
color(255, ((170)+(170/steps)*j), 255/steps*j),
color(255, ((127)+(127/steps)*j), (255/steps)*j),
color(255, ((102)+(102/(steps-2))*j), (255/steps)*j),
color(255, (255/steps)*j, ((255)/steps)*j),
color(255, (255/steps)*j, ((127)+(127/steps)*j)),
color(255, (255/steps)*j, 255),
color(((127)+(127/steps)*j), (255/steps)*j, 255),
color(((255)/steps)*j, (255/steps)*j, 255),
color((255/steps)*j, 255, ((102)+(102/steps)*j)),
color((255/(steps))*j, 255, (255/(steps))*j),
color(((127)+(127/steps)*j), 255, (255/steps)*j)
};
for (int i = 0; i < segs; i++) {
fill(cols[i]);
arc(width/2, height/2, radius, radius,
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}
#define RED_PIN 3
#define BLUE_PIN 5
#define GREEN_PIN 6
#define NUM_BYTES 3
char led_color[NUM_BYTES] = {0, };
unsigned char R, G, B;
void RGB(unsigned char r, unsigned char g, unsigned char b) {
analogWrite(RED_PIN, r);
analogWrite(BLUE_PIN, b);
analogWrite(GREEN_PIN, g);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available() == 0);
Serial.readBytes(led_color, NUM_BYTES);
R = (unsigned char)(led_color[0]);
G = (unsigned char)(led_color[1]);
B = (unsigned char)(led_color[2]);
RGB(R, G, B);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment