Skip to content

Instantly share code, notes, and snippets.

@jeffnoko
Created January 9, 2018 06:06
Show Gist options
  • Save jeffnoko/91a649d70abe8e67e06d110d93fdc3ad to your computer and use it in GitHub Desktop.
Save jeffnoko/91a649d70abe8e67e06d110d93fdc3ad to your computer and use it in GitHub Desktop.
Use pots connected to Arduino to make a bezier curve in Processing
// Bezier curve to visualize for drawing on xy machine.
import processing.serial.*;
Serial myPort;
float a,b,c,d,e,f,g,h;
float aa,bb,cc,dd,ee,ff,gg,hh;
String val;
boolean firstContact = false;
int end = 10;
String serial;
int[] pos = new int[8];
void setup(){
myPort = new Serial(this, Serial.list()[0],9600);
myPort.clear();
serial = myPort.readStringUntil(end);
serial = null;
size(1000, 1000);
background(0);
stroke(255);
noFill();
smooth();
}
void draw(){
background(0);
while (myPort.available() > 0) {
serial = myPort.readStringUntil(end);
}
if (serial != null) {
String numbers = serial;
float[] pos = float(split(numbers, ','));
print(pos[0]);
print(" ");
a = pos[0];
print(pos[1]);
print(" ");
b = pos[1];
print(pos[2]);
print(" ");
c = pos[2];
print(pos[3]);
print(" ");
d = pos[3];
print(pos[4]);
print(" ");
e = pos[4];
print(pos[5]);
print(" ");
f= pos[5];
print(pos[6]);
print(" ");
g= pos[6];
println(pos[7]);
h = pos[7];
}
delay(1000);
bezier(a, b, c, d, e, f, g, h);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment