I am very new to processing but each day i learn a new thing. Here is my setup explained below.
I have a Variable resistor connected to Arduino A0 pin and when it turns the serial data goes to PC and in the processing i draw some thing like in the image. Assume the grey color object is a flap of an ROV.
Now i turn the VR it moves to both direction. What i want is when i send 5 degrees it should go 5 degrees and when i send negative 5 degrees or some other way it should go down.
Arduino code
int vr = 0;
float midvr = 90;
float vrdef = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println(analogRead(A0));
delay(200);
}
Processing code
import processing.serial.*;
Serial myPort;// serial port
float r = 0;
float d = 90;
void setup(){
size(400,400);
background(147,147,147);
rectMode(CENTER);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
//rotate(0);z
//rect(0,0,200,20);
frameRate(20);
noStroke();
smooth();
}
void draw(){
background(147,147,147);
fill(165,232,42);
translate(width/2,height/2);
//translate(mouseX,mouseY);
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0,180 );
//println(inByte);
float deg = inByte;
float rad = radians(deg);
// if(deg >= d){
//
// rotate(rad/2);
// // rotate(rad);
// ellipse(0, 0, 200, 25);
//
// } else if (deg <= d) {
//
// rotate(rad/2);
// ellipse(0, 0, 200, 25);
// } else if (deg == 0); {
//
// rotate(rad/2);
// ellipse(0, 0, 200, 25);}
//float deg = degrees(rad);
println(rad + " radians is " + deg + " degrees");
rotate(rad);
textSize(32);
text(deg + " °",0,50);
// text(" °");
//rect(0,0,200,20);
ellipse(0, 0, 200, 25);
//r= inByte + 1;
}
}
Hope to get a solution or some guidelines to follow