Created
November 20, 2017 06:26
-
-
Save ulrichzwingli/17f84ebb0858257163c42e05fd388091 to your computer and use it in GitHub Desktop.
Project : Face Your Fear (Processing code for processing controlling servo)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
PVector a = new PVector(150, 0); | |
PVector b = new PVector(0, 150); | |
float angle; | |
Serial myPort; // Create object from Serial class | |
PVector v1; | |
PVector v2; | |
//float a; | |
void setup() | |
{ | |
size(300,300); //make our canvas 200 x 200 pixels big | |
smooth(); | |
String portName = Serial.list()[3]; //change the 0 to a 1 or 2 etc. to match your port | |
myPort = new Serial(this, portName, 9600); | |
} | |
void draw() { | |
background(255); | |
translate(width/2, height/2); | |
fill(0); | |
line(0, 0, a.x, a.y); | |
line(0, 0, b.x, b.y); | |
ellipse(a.x, a.y, 15, 15); | |
ellipse(b.x, b.y, 15, 15); | |
b.set(mouseX-width/2, mouseY-height/2, 0); | |
angle = PVector.angleBetween(a, b); | |
println(int(degrees(angle))); | |
myPort.write(int(degrees(angle))/2); | |
text(int(degrees(angle)), 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment