ciao a tutti , se qualcuno ha cortesemente un'idea lo ringrazio in anticipo ho interfacciato arduino e processing nel tentativo di fare muovere delle immagini su processing tramite sensori multipli , cominciando con lo schetck dell'albero ,che posto qui sotto ,se provo col potenziometro funziona, ma col sensore sharp 2d f86 mi fa tutto uno scatto..su arduino carico la libreria standard firmdata.
questo è per processing:
import processing.serial.*; // reference the serial library
import cc.arduino.*; // reference the arduino library
Arduino arduino; // create a variable arduino of the Arduino data type
float theta;
void setup() {
size(600,600);
smooth();
println(Serial.list()); // List all the available serial ports:
arduino = new Arduino(this, Arduino.list()[3], 57600);
}
void draw() {
background(0);
frameRate(30);
stroke(255);
// Let's pick an angle 0 to 90 degrees based on the mouse position
/* float a = (mouseX / (float) width) * 90f; // original line */
float a = (arduino.analogRead(0) / (float) width) * 90f;
// Convert it to radians
theta = radians(a);
// Start the tree from the bottom of the screen
translate(width/2,height);
// Draw a line 60 pixels
line(0,0,0,-60);
// Move to the end of that line
translate(0,-60);
// Start the recursive branching!
branch(60);
}
void branch(float h) {
// Each branch will be 2/3rds the size of the previous one
h *= 0.66f;
// All recursive functions must have an exit condition!!!!
// Here, ours is when the length of the branch is 2 pixels or less
if (h > 2) {
pushMatrix(); // Save the current state of transformation (i.e. where are we now)
rotate(theta); // Rotate by theta
line(0,0,0,-h); // Draw the branch
translate(0,-h); // Move to the end of the branch
branch(h); // Ok, now call myself to draw two new branches!!
popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
// Repeat the same thing, only branch off to the "left" this time!
pushMatrix();
rotate(-theta);
line(0,0,0,-h);
translate(0,-h);
branch(h);
popMatrix();
}
}