Skip to content

Instantly share code, notes, and snippets.

@companje
Last active May 17, 2024 22:20
Show Gist options
  • Save companje/0e95822163ecdd734b1cb2603f922a60 to your computer and use it in GitHub Desktop.
Save companje/0e95822163ecdd734b1cb2603f922a60 to your computer and use it in GitHub Desktop.
Lerp / Blend color - blue+yellow and cyan+yellow
import processing.serial.*;
int h=40;
Serial port;
void setup() {
size(320, 320);
background(0);
port = new Serial(this, "/dev/cu.usbmodem21401", 9600);
}
void draw() {
while (port.available() > 0) {
int i = port.read()-'A';
boolean r = (i&1)!=0;
boolean g = (i&2)!=0;
boolean b = (i&4)!=0;
boolean y = (i&8)!=0;
boolean k = (i&16)!=0;
boolean w = (i&32)!=0;
color rgb = color(r?255:0, g?255:0, b?255:0);
color rgby = y ? b&&g&&!r ? #88ff77 : b&&!r ? #00ff00 : (r||g||b) ? lerpColor(rgb, #ffff00, .5) : #ffff00 : rgb;
color rgbyk = k ? lerpColor(rgby, #000000, .5) : rgby ;
color rgbykw = w ? (r||g||b||y||k) ? lerpColor(rgbyk, #ffffff, .5) : color(255) : rgbyk ;
background(rgbykw);
}
}
const int pins[] = { 8, 9, 10, 11, 12, 13 }; //red green blue yellow black white
const int numButtons = sizeof(pins) / sizeof(pins[0]);
void setup() {
for (int i = 0; i < numButtons; i++) {
pinMode(pins[i], INPUT_PULLUP);
}
Serial.begin(9600);
}
void loop() {
char b = 0;
for (int i = 0; i < numButtons; i++) {
if (!digitalRead(pins[i])) b |= (1 << i);
}
Serial.write(b+'A');
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment