Skip to content

Instantly share code, notes, and snippets.

@aaronparsekian aaronparsekian/rgbw
Created Oct 16, 2015

Embed
What would you like to do?
var serial; // variable to hold an instance of the serialport library
var portName = '/dev/cu.usbmodem1411'; // fill in your serial port name here
//var portName = '/dev/cu.AdafruitEZ-Link744f-SPP'; // fill in your serial port name here
var outByte1; // for outgoing data
var outByte2;
var outByte3;
var outByte4;
var slider1;
var slider2;
var slider3;
var slider4;
var canvas;
function setup() {
canvas = createCanvas(300, 300);
canvas.position(100, 100);
serial = new p5.SerialPort(); // make a new instance of the serialport library
serial.on('error', serialError); // callback for errors
serial.open(portName); // open a serial port
slider1 = createSlider(0, 255, 255);
slider1.position(400, 150);
slider2 = createSlider(0, 255, 255);
slider2.position(400, 200);
slider3 = createSlider(0, 255, 255);
slider3.position(400, 250);
slider4 = createSlider(0, 255, 255);
slider4.position(400, 300);
slider1.rotate(180);
slider2.rotate(180);
slider3.rotate(180);
slider4.rotate(180);
}
function serialError(err) {
println('Something went wrong with the serial port. ' + err);
}
function draw() {
// black background, white text:
background(200);
fill(150);
// display the incoming serial data as a string:
text("RGBW: " + outByte1 + ',' + outByte2 + ',' + outByte3 + ',' + outByte4, 20, 30);
var slideVal1 = slider1.value();
outByte1 = slideVal1;
var slideVal2 = slider2.value();
outByte2 = slideVal2;
var slideVal3 = slider3.value();
outByte3 = slideVal3;
var slideVal4 = slider4.value();
outByte4 = slideVal4;
serial.write(outByte1 + ',' + outByte2 + ',' + outByte3 + ',' + outByte4 + '\n');
fill(map(outByte1, 0, 255, 255, 0), map(outByte2, 0, 255, 255, 0), map(outByte3, 0, 255, 255, 0), 100);
ellipse(150, 150, 100, 100);
fill(map(outByte4, 0, 255, 255, 0), map(outByte4, 0, 255, 255, 0), map(outByte4, 0, 255, 255, 0), map(outByte4, 0, 255, 255, 0), 100);
ellipse(150, 150, 100, 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.