» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » Faire passer un objet en mouvement devant un autre : http://codelab.fr/1379 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : Faire passer un objet en mouvement devant un autre |
fdrg — 2009-11-16 18:05:32 |
Bonjour à tous! Code (p5) :import processing.opengl.*; PImage bg ; PImage texmap; float globeRadius = 450; float universeRadius = 1400; float[] cx, cz, sphereX, sphereY, sphereZ; float sinLUT[]; float cosLUT[]; float SINCOS_PRECISION = 0.5; int SINCOS_LENGTH = int(360.0 / SINCOS_PRECISION); float a; int sDetail = 35; void setup() { size(1440, 900, OPENGL); bg = loadImage("tuto_h16_5-698da.jpg"); initializeSphere(sDetail); texmap = loadImage("carte_monde.jpg"); initializeSphere(sDetail); } void draw() { background(0); translate(width/2, height/2); pushMatrix(); noFill(); stroke(255,200); strokeWeight(2); smooth(); popMatrix(); lights(); fill(200); noStroke(); textureMode(IMAGE); textureMode(IMAGE); rotateY(a*2); rotateX(radians(-23)); rotateY(radians(-23)); rotateX(1/2*PI); a += 0.01; renderUniverse(); renderGlobe(); } void renderUniverse () { textureMode (IMAGE); texturedSphere(universeRadius, bg); } void renderGlobe() { textureMode(IMAGE); texturedSphere(globeRadius, texmap); } void initializeSphere(int res) { sinLUT = new float[SINCOS_LENGTH]; cosLUT = new float[SINCOS_LENGTH]; for (int i = 0; i < SINCOS_LENGTH; i++) { sinLUT[i] = (float) Math.sin(i * DEG_TO_RAD * SINCOS_PRECISION); cosLUT[i] = (float) Math.cos(i * DEG_TO_RAD * SINCOS_PRECISION); } float delta = (float)SINCOS_LENGTH/res; float[] cx = new float[res]; float[] cz = new float[res]; // Calc unit circle in XZ plane for (int i = 0; i < res; i++) { cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH]; cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH]; } // Computing vertexlist vertexlist starts at south pole int vertCount = res * (res-1) + 2; int currVert = 0; // Re-init arrays to store vertices sphereX = new float[vertCount]; sphereY = new float[vertCount]; sphereZ = new float[vertCount]; float angle_step = (SINCOS_LENGTH*0.5f)/res; float angle = angle_step; // Step along Y axis for (int i = 1; i < res; i++) { float curradius = sinLUT[(int) angle % SINCOS_LENGTH]; float currY = -cosLUT[(int) angle % SINCOS_LENGTH]; for (int j = 0; j < res; j++) { sphereX[currVert] = cx[j] * curradius; sphereY[currVert] = currY; sphereZ[currVert++] = cz[j] * curradius; } angle += angle_step; } sDetail = res; } // Generic routine to draw textured sphere void texturedSphere(float r, PImage t) { int v1,v11,v2; r = (r + 240 ) * 0.33; beginShape(TRIANGLE_STRIP); texture(t); float iu=(float)(t.width-1)/(sDetail); float iv=(float)(t.height-1)/(sDetail); float u=0,v=iv; for (int i = 0; i < sDetail; i++) { vertex(0, -r, 0,u,0); vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v); u+=iu; } vertex(0, -r, 0,u,0); vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v); endShape(); // Middle rings int voff = 0; for(int i = 2; i < sDetail; i++) { v1=v11=voff; voff += sDetail; v2=voff; u=0; beginShape(TRIANGLE_STRIP); texture(t); for (int j = 0; j < sDetail; j++) { vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv); u+=iu; } // Close each ring v1=v11; v2=voff; vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv); endShape(); v+=iv; } u=0; // Add the northern cap beginShape(TRIANGLE_STRIP); texture(t); for (int i = 0; i < sDetail; i++) { v2 = voff + i; vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v); vertex(0, r, 0,u,v+iv); u+=iu; } vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v); endShape(); } ceci est la premiere partie de mon travail. Dans un second temps ; pour une explication complete, je souhaite que la vitesse de rotation du globe fluctue selon les variations de battement cardiaque. mais ceci sera une autre etape que j'espere pouvoir resoudre. |
fdrg — 2009-11-17 10:03:03 |
En fait, apres réflexion, je crois que mon probleme se trouve etre une question de classe à creer! mais ouha, je ne comprends pas bien comment l'integrer dans ce sketch. est-il possible de creer une classe avec PImage? |
emoc — 2009-11-17 15:05:10 |
Bonjour et bienvenue, |
fdrg — 2009-11-17 18:24:31 |
Bonsoir, et un grand merci!! |
emoc — 2009-11-18 10:18:56 |
En utilisant le sketch tel qu'il est, tu peux très bien modifier les deux vitesses de rotation indépendamment, en créant une variable pour chacune (float a, b; plutot que float a; ), ces variables sont modifiées en fonction des données de tes capteurs. Pour faire tourner les objets indépendamment, une structure comme ça dans le draw() fera l'affaire : a += 0.01; b += 0.05 rotateY(a); renderUniverse(); rotateY(b); renderGlobe(); Voila pour la solution minimum, tu peux aussi créer des classes et inclure les coordonnées de position, rotation dans les instances d'objet, mais ce serait surtout utile si tu multipliais les globes, et ça t'oblige à refondre tout le code. |
22_79 — 2009-11-18 11:50:03 |
Salut fdrg, |
fdrg — 2009-11-18 18:00:40 |
Bonsoir, |
emoc — 2009-11-18 18:46:43 |
Oui, tiens nous au courant de tes avancées |
fdrg — 2009-11-23 15:17:23 |
Bonjour, Code (processing) :import processing.serial.*; Serial myPort; // Create object from Serial class float val; // Data received from the serial port import processing.opengl.*; PImage bg ; PImage texmap; float globeRadius = 450; float universeRadius = 2000; float[] cx, cz, sphereX, sphereY, sphereZ; float sinLUT[]; float cosLUT[]; float SINCOS_PRECISION = 0.5; int SINCOS_LENGTH = int(360.0 / SINCOS_PRECISION); float a, b ; int sDetail = 35; void setup() { size(1440, 800, OPENGL); bg = loadImage("tuto_h16_5-698da.jpg"); initializeSphere(sDetail); texmap = loadImage("carte_monde.jpg"); initializeSphere(sDetail); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); } void draw() { background(0); translate(width/2, height/2); pushMatrix(); noFill(); stroke(255,200); strokeWeight(2); smooth(); popMatrix(); specular(0, 0, 0); fill(200); noStroke(); textureMode(IMAGE); textureMode(IMAGE); rotateY(a*2); rotateX(radians(-23)); rotateY(radians(-23)); rotateX(1/2*PI); a += 0.01; b += val; renderUniverse(); rotateY(b); renderGlobe(); if ( myPort.available() > 0) { // If data is available, val = myPort.read(); // read it and store it in val } } void renderUniverse () { textureMode (IMAGE); texturedSphere(universeRadius, bg); } void renderGlobe() { textureMode(IMAGE); texturedSphere(globeRadius, texmap); } void initializeSphere(int res) { sinLUT = new float[SINCOS_LENGTH]; cosLUT = new float[SINCOS_LENGTH]; for (int i = 0; i < SINCOS_LENGTH; i++) { sinLUT[i] = (float) Math.sin(i * DEG_TO_RAD * SINCOS_PRECISION); cosLUT[i] = (float) Math.cos(i * DEG_TO_RAD * SINCOS_PRECISION); } float delta = (float)SINCOS_LENGTH/res; float[] cx = new float[res]; float[] cz = new float[res]; // Calc unit circle in XZ plane for (int i = 0; i < res; i++) { cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH]; cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH]; } // Computing vertexlist vertexlist starts at south pole int vertCount = res * (res-1) + 2; int currVert = 0; // Re-init arrays to store vertices sphereX = new float[vertCount]; sphereY = new float[vertCount]; sphereZ = new float[vertCount]; float angle_step = (SINCOS_LENGTH*0.5f)/res; float angle = angle_step; // Step along Y axis for (int i = 1; i < res; i++) { float curradius = sinLUT[(int) angle % SINCOS_LENGTH]; float currY = -cosLUT[(int) angle % SINCOS_LENGTH]; for (int j = 0; j < res; j++) { sphereX[currVert] = cx[j] * curradius; sphereY[currVert] = currY; sphereZ[currVert++] = cz[j] * curradius; } angle += angle_step; } sDetail = res; } // Generic routine to draw textured sphere void texturedSphere(float r, PImage t) { int v1,v11,v2; r = (r + 240 ) * 0.33; beginShape(TRIANGLE_STRIP); texture(t); float iu=(float)(t.width-1)/(sDetail); float iv=(float)(t.height-1)/(sDetail); float u=0,v=iv; for (int i = 0; i < sDetail; i++) { vertex(0, -r, 0,u,0); vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v); u+=iu; } vertex(0, -r, 0,u,0); vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v); endShape(); // Middle rings int voff = 0; for(int i = 2; i < sDetail; i++) { v1=v11=voff; voff += sDetail; v2=voff; u=0; beginShape(TRIANGLE_STRIP); texture(t); for (int j = 0; j < sDetail; j++) { vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv); u+=iu; } // Close each ring v1=v11; v2=voff; vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv); endShape(); v+=iv; } u=0; // Add the northern cap beginShape(TRIANGLE_STRIP); texture(t); for (int i = 0; i < sDetail; i++) { v2 = voff + i; vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v); vertex(0, r, 0,u,v+iv); u+=iu; } vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v); endShape(); } et rien.... Code (processing) :import processing.serial.*; Serial myPort; // The serial port int yPos = 1; // horizontal position of the graph void setup () { size( 400, 300); // List all the available serial ports println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); // set inital background: background(0); } void draw () { // everything happens in the serialEvent() } void serialEvent (Serial myPort) { // get the ASCII string: 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, height); // draw the line: stroke(127,34,255); line(yPos, height, yPos, height - inByte); // at the edge of the screen, go back to the beginning: if (yPos >= width) { yPos = 0; background(0); } else { // increment the horizontal position: yPos++; } } } et rien non plus. void setup() { // initialize the serial communication: Serial.begin(9600); } void loop() { // send the value of analog input 0: Serial.println(analogRead(0)); // wait a bit for the analog-to-digital converter // to stabilize after the last reading: delay(10); } j'avoue que je ne n'arrive pas à comprendre pourquoi cela ne fonctionne pas, mais je continu à potasser! |
emoc — 2009-11-24 09:23:21 |
C'est normal, Arduino envoie la valeur du potentiomètre en permanence (toutes les 10 millisecondes, en fait). Processing reçoit donc de nouvelles données en permanence, et comme ta boucle draw se répète aussi vite que le permet ta machine, à chaque rafraichissement b += val; et ton globe tourne de plus en plus vite. |
fdrg — 2009-11-24 11:22:39 |
en fait en utilisant que se soit b = val, b = val/100 ou autre le globe saccade à present. je suis paumé... |
emoc — 2009-11-24 15:10:51 |
Je ne sais pas trop ou tu en es dans ton code, renvoie peut-être une version actualisée. |
fdrg — 2009-11-24 17:38:17 |
En fait oui je cherche à ajouter une accélération à la vitesse de rotation du globe par le potentiomètre dans un premier temps pour pouvoir comprendre se qui se passe, puis par le cardiofrequencemetre ensuite. Cela sera la vitesse du rythme cardiaque qui va commander la vitesse de rotation du globe. Voilà un lien pour le cardiofrequencemetre : http://www.ecole-art-aix.fr/article2963.html Code (processing) :import processing.serial.*; Serial myPort; // Create object from Serial class float val; // Data received from the serial port import processing.opengl.*; PImage bg ; PImage texmap; float globeRadius = 450; float universeRadius = 2000; float[] cx, cz, sphereX, sphereY, sphereZ; float sinLUT[]; float cosLUT[]; float SINCOS_PRECISION = 0.5; int SINCOS_LENGTH = int(360.0 / SINCOS_PRECISION); float a, b ; int sDetail = 35; void setup() { size(1440, 800, OPENGL); bg = loadImage("tuto_h16_5-698da.jpg"); initializeSphere(sDetail); texmap = loadImage("carte_monde.jpg"); initializeSphere(sDetail); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); } void draw() { background(0); translate(width/2, height/2); pushMatrix(); noFill(); stroke(255,200); strokeWeight(2); smooth(); popMatrix(); specular(0, 0, 0); fill(200); noStroke(); textureMode(IMAGE); textureMode(IMAGE); rotateY(a*2); rotateX(radians(-23)); rotateY(radians(-23)); rotateX(1/2*PI); a += 0.01; b = val; renderUniverse(); rotateY(b); renderGlobe(); if ( myPort.available() > 0) { // If data is available, val = myPort.read(); // read it and store it in val } } void renderUniverse () { textureMode (IMAGE); texturedSphere(universeRadius, bg); } void renderGlobe() { textureMode(IMAGE); texturedSphere(globeRadius, texmap); } void initializeSphere(int res) { sinLUT = new float[SINCOS_LENGTH]; cosLUT = new float[SINCOS_LENGTH]; for (int i = 0; i < SINCOS_LENGTH; i++) { sinLUT[i] = (float) Math.sin(i * DEG_TO_RAD * SINCOS_PRECISION); cosLUT[i] = (float) Math.cos(i * DEG_TO_RAD * SINCOS_PRECISION); } float delta = (float)SINCOS_LENGTH/res; float[] cx = new float[res]; float[] cz = new float[res]; // Calc unit circle in XZ plane for (int i = 0; i < res; i++) { cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH]; cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH]; } // Computing vertexlist vertexlist starts at south pole int vertCount = res * (res-1) + 2; int currVert = 0; // Re-init arrays to store vertices sphereX = new float[vertCount]; sphereY = new float[vertCount]; sphereZ = new float[vertCount]; float angle_step = (SINCOS_LENGTH*0.5f)/res; float angle = angle_step; // Step along Y axis for (int i = 1; i < res; i++) { float curradius = sinLUT[(int) angle % SINCOS_LENGTH]; float currY = -cosLUT[(int) angle % SINCOS_LENGTH]; for (int j = 0; j < res; j++) { sphereX[currVert] = cx[j] * curradius; sphereY[currVert] = currY; sphereZ[currVert++] = cz[j] * curradius; } angle += angle_step; } sDetail = res; } // Generic routine to draw textured sphere void texturedSphere(float r, PImage t) { int v1,v11,v2; r = (r + 240 ) * 0.33; beginShape(TRIANGLE_STRIP); texture(t); float iu=(float)(t.width-1)/(sDetail); float iv=(float)(t.height-1)/(sDetail); float u=0,v=iv; for (int i = 0; i < sDetail; i++) { vertex(0, -r, 0,u,0); vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v); u+=iu; } vertex(0, -r, 0,u,0); vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v); endShape(); // Middle rings int voff = 0; for(int i = 2; i < sDetail; i++) { v1=v11=voff; voff += sDetail; v2=voff; u=0; beginShape(TRIANGLE_STRIP); texture(t); for (int j = 0; j < sDetail; j++) { vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv); u+=iu; } // Close each ring v1=v11; v2=voff; vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv); endShape(); v+=iv; } u=0; // Add the northern cap beginShape(TRIANGLE_STRIP); texture(t); for (int i = 0; i < sDetail; i++) { v2 = voff + i; vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v); vertex(0, r, 0,u,v+iv); u+=iu; } vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v); endShape(); } |
emoc — 2009-11-25 20:57:21 |
Hello, |
fdrg — 2009-11-26 10:33:32 |
Salut, |
emoc — 2009-11-27 13:43:44 |
Salut, Code (processing) :import processing.serial.*; Serial myPort; // Create object from Serial class float val; // Data received from the serial port import processing.opengl.*; PImage bg ; PImage texmap; float globeRadius = 450; float universeRadius = 2000; float[] cx, cz, sphereX, sphereY, sphereZ; float sinLUT[]; float cosLUT[]; float SINCOS_PRECISION = 0.5; int SINCOS_LENGTH = int(360.0 / SINCOS_PRECISION); float a, b ; int sDetail = 35; float battement = 80; void setup() { size(1440, 800, OPENGL); bg = loadImage("img1.jpg"); initializeSphere(sDetail); texmap = loadImage("img2.jpg"); initializeSphere(sDetail); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); } void draw() { background(0); translate(width/2, height/2); smooth(); specular(0, 0, 0); noStroke(); // rotation de l'univers pushMatrix(); a += 0.01; rotateY(a*2); rotateX(1 / TWO_PI); renderUniverse(); popMatrix(); // rotation du globe pushMatrix(); if ( myPort.available() > 0) { // If data is available, val = myPort.read(); // read it and store it in val battement = map(val, 0, 1023, 60, 180); } b += 0.01 + (battement - 60) / 300; rotateY(b); renderGlobe(); popMatrix(); } void renderUniverse () { textureMode (IMAGE); texturedSphere(universeRadius, bg); } void renderGlobe() { textureMode(IMAGE); texturedSphere(globeRadius, texmap); } void keyPressed() { if (key == '+') battement ++; if (key == '-') battement --; if (key == 'p') println("battement : " + battement); } void initializeSphere(int res) { sinLUT = new float[SINCOS_LENGTH]; cosLUT = new float[SINCOS_LENGTH]; for (int i = 0; i < SINCOS_LENGTH; i++) { sinLUT[i] = (float) Math.sin(i * DEG_TO_RAD * SINCOS_PRECISION); cosLUT[i] = (float) Math.cos(i * DEG_TO_RAD * SINCOS_PRECISION); } float delta = (float)SINCOS_LENGTH/res; float[] cx = new float[res]; float[] cz = new float[res]; // Calc unit circle in XZ plane for (int i = 0; i < res; i++) { cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH]; cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH]; } // Computing vertexlist vertexlist starts at south pole int vertCount = res * (res-1) + 2; int currVert = 0; // Re-init arrays to store vertices sphereX = new float[vertCount]; sphereY = new float[vertCount]; sphereZ = new float[vertCount]; float angle_step = (SINCOS_LENGTH*0.5f)/res; float angle = angle_step; // Step along Y axis for (int i = 1; i < res; i++) { float curradius = sinLUT[(int) angle % SINCOS_LENGTH]; float currY = -cosLUT[(int) angle % SINCOS_LENGTH]; for (int j = 0; j < res; j++) { sphereX[currVert] = cx[j] * curradius; sphereY[currVert] = currY; sphereZ[currVert++] = cz[j] * curradius; } angle += angle_step; } sDetail = res; } // Generic routine to draw textured sphere void texturedSphere(float r, PImage t) { int v1,v11,v2; r = (r + 240 ) * 0.33; beginShape(TRIANGLE_STRIP); texture(t); float iu=(float)(t.width-1)/(sDetail); float iv=(float)(t.height-1)/(sDetail); float u=0,v=iv; for (int i = 0; i < sDetail; i++) { vertex(0, -r, 0,u,0); vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v); u+=iu; } vertex(0, -r, 0,u,0); vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v); endShape(); // Middle rings int voff = 0; for(int i = 2; i < sDetail; i++) { v1=v11=voff; voff += sDetail; v2=voff; u=0; beginShape(TRIANGLE_STRIP); texture(t); for (int j = 0; j < sDetail; j++) { vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv); u+=iu; } // Close each ring v1=v11; v2=voff; vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v); vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv); endShape(); v+=iv; } u=0; // Add the northern cap beginShape(TRIANGLE_STRIP); texture(t); for (int i = 0; i < sDetail; i++) { v2 = voff + i; vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v); vertex(0, r, 0,u,v+iv); u+=iu; } vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v); endShape(); } |
fdrg — 2009-11-29 17:21:45 |
Salut, |
emoc — 2009-12-01 19:31:51 |
C'est normal que tu ne vois pas grand chose changer entre 60 et 65, l'écart maximum est prévu entre 60 et 180, et donc avec une différence de 5, il ne se passe pas grand chose. Par contre, c'est bizarre que ton potentiomètre ne produise pas un écart plus important. Tu devrais tester les valeurs reçues avec un sketch très simple (juste recevoir les valeurs et les afficher en println), ça permettra de savoir s'il envoie bien des valeurs entre 0 et 1023
C'est normal qu'il ne se passe rien avec keypressed si ton potentiomètre est relié, les valeurs envoyées par arduino définissent le battement, en passant par dessus celles des touches. J'ai utilisé ça car je n'ai pas de potentiomètre / arduino relié, essaie le sketch sans le relier et tu pourras visualiser la "gamme" de vitesse en utilisant le clavier.
Oui c'est logique, le potentiomètre est un composant analogique, par contre je ne peux pas savoir si ton programme arduino déconne, envoie le si tu veux, ou testes avec le sketch très simple comme je te propose plus haut, tu verras si les valeurs sont bien envoyées. |
fdrg — 2009-12-11 17:36:15 |
Salut et merci de ta réponse. Code (processing) :void setup() { // initialize the serial communication: Serial.begin(9600); } void loop() { // send the value of analog input 0: Serial.println(analogRead(0)); // wait a bit for the analog-to-digital converter // to stabilize after the last reading: delay(10); } je donnerai des nouvelles dès que possible |
emoc — 2009-12-15 23:28:01 |
ok, à suivre donc... Mais il ne manque pas des trucs dans ton programme pour arduino, la définition du port d'entrée par exemple ? |
fdrg — 2010-03-22 10:12:24 |
Bonjour à tous le monde! Code (processing) :Par contre je rencontre encore un petit souci qui est que mon globe tourne à présent dans un sens puis dans l'autre. Je pense que c'est du à la polarité, mais je n'ai pas d'idée pour modifier cela dans mon code afin que l' globe ne tourne plus que dans un sens. Est-ce possible? |
emoc — 2010-03-23 17:38:55 |
Salut, |
fdrg — 2010-03-23 20:38:38 |
Salut et merci Emoc, |
emoc — 2010-03-23 21:55:56 |
b correspond à l'angle de rotation Y, il est mis à jour à chaque passage dans draw(), c'est à dire selon le framerate (que tu ne définis pas, donc "aussi vite que possible"), donc l'angle est renouvelé à chaque fois |
fdrg — 2010-03-24 13:45:09 |
Merci Emoc. |
emoc — 2010-03-24 14:15:47 |
C'est normal, au vu des valeurs pour des angles en radians
A priori, à chaque passage dans draw, la valeur est lue directement sur l'entrée analogique de l'arduino, donc ce sont les valeurs qui viennent du capteur. D'ailleurs que capte réellement ce capteur et que signifient ces valeurs? Dans le petit extrait que tu donnes, on voit bien que ça dessine une courbe avec un pic à 283 puis ça descend et ça remonte. |
fdrg — 2010-03-24 15:32:11 |
Et bien mon capteur est un cardio-fréquencemètre et capte le rythme cardiaque de mon coeur via une ceinture thoracique. Maintenant je me demande si l'utilisation d'un oxymètre que l'on placerait sur un doigt ne serait pas plus précise. Code (processing) :En fait je ne sais pas comment faire pour que String inString interagisse par rapport à Arduino. J'ai pas mal de chose à apprendre encore! |
emoc — 2010-03-24 15:56:38 |
Oui oui, mais que transmet il ? Ce que je veux dire, c'est que je pense que le capteur permet de retrouver la pulsation cardiaque mais qu'il ne transmet pas directement la pulsation. Ce que tu veux obtenir, c'est la pulsation, 90 par exemple, si le capteur transmettait ça, 'b' oscillerait autour de 90 (une fois quelques secondes passées pour obtenir la première valeur). Mais, au vu des valeurs, ça ne marche pas comme ça :) |
fdrg — 2010-03-24 16:59:58 |
Je comprends mieux ta question. En fait se que je capte du cardio-fréquencemètre c'est un signal électrique qui varie à peu près entre 0 et 0,2 volt au voltmètre (mon matos est un peu vieux donc pas vraiment précis je pense). |
emoc — 2010-03-24 17:28:48 |
Oui, il y a un traitement à appliquer pour extraire la pulsation de ce signal. |
fdrg — 2010-03-25 15:38:48 |
Ok merci, Code (processing) : |
emoc — 2010-03-25 15:48:37 |
Non, je ne crois pas que ça suffise, le niveau électrique ne renvoie pas la pulsation, la correspondance ne peut pas être établie comme ça, tu devrais y voir plus clair avec le graphique
Essaie d'enlever le test (if (inInt != null)), inutile maitenant que ce n'est plus une string |
fdrg — 2010-03-29 15:51:06 |
Salut, Code (processing) :Mais à ma grande déception il ne se passe rien dans le graphique. Là je suis franchement perdu. |
emoc — 2010-03-29 16:10:06 |
Enlever (if (inInt != null)) ok, mais il faut aussi que tu enlèves les crochets { et } (lignes 29 et 48) qui correspondaient au test if |
fdrg — 2010-03-29 17:09:55 |
J'ai bien enlevé les deux crochets mais le problème persiste. |
fdrg — 2010-04-09 20:53:46 |
Salut, Code (processing) :Bon maintenant il me reste à trouver le moyen de faire fonctionner cela avec un capteur cardiaque... |