Hey guys, i made a program to read a gyroscope and display data at processing. I wanna display the data like a circle with a line at mid indicating the angle.
thats is the
Code:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin = 13;
int buttonPin = 8;
int minimo=300, maximo=0;
float value=0;
float first_time, time;
float teta=0;
void setup()
{
size(400,400);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1]); // v2
//arduino = new Arduino(this, Arduino.list()[0], 57600); // v1
arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(buttonPin, Arduino.INPUT);
arc(200,200,100,100,0,TWO_PI);
frameRate(60);
delay(7);
}
float sens= 0.512;
float offset= 320;
float count= 0;
float valor =0;
float aux1=0,aux2=0;
int[] contador={0,0,0};
void draw() {
first_time=millis();
if (mousePressed == true) {
fill(255,0,0);
aux1=0;
aux2=0;
contador[0]=0;
contador[1]=0;
contador[2]=0;
teta=0;
arduino.digitalWrite(ledPin, Arduino.HIGH);
} else {
fill(0,0,0);
arduino.digitalWrite(ledPin, Arduino.LOW);
}
//####################################################################//
// //
// Gyro //
// Sensibilidade 2.5mV/ º/s = 0.512 counts/ º/s //
// Offset 320 counts = 1562mV = 1.562V //
// 4.88 mV/count // 0.2048 count/mV //
// //
//####################################################################//
count =0;
for(int i=0;i<20;i++){
count = count + arduino.analogRead(0);
}
count = count /20;
if((int)count==319) contador[0]=contador[0]+1;
if((int)count==320) contador[1]=contador[1]+1;
if((int)count==321) contador[2]=contador[2]+1;
valor = (count - offset ) / sens;
aux1=aux1+(int)count;
aux2=aux2+(int)valor;
//line(200,200,200*cos(teta),200*sin(teta));
println("count: "+(int)count+" valor: "+valor);
println("soma1: "+aux1+" soma2: "+aux2);
println("319: "+contador[0]+" 320: "+contador[1]+" 321: "+contador[2]);
//println("cos: "+cos(valor)+" sin: "+sin(valor));
println();
time=millis()-first_time;
println("tempo: "+time);
teta=teta+valor*time/1000;
println("teta: "+teta);
line(200,200,100*cos(radians(teta))+200,100*sin(radians(teta))+200);
}
but, when the data is displayed the line overwrite the previews line. how to fix this.
the code is a little exstensive.
ty guys