Ok merci,
il faudrait donc en fait que j'établisse un rapport entre le signal électrique d'entré et un rythme de rotation. Par exemple entre 0 0.05v, un battement de 60, 0.10v, 70 etc. Puis pour chaque rythme une vitesse de rotation du globe adapté à Processing. Il y à du taf!!
Sinon pour le code du graphique j'ai modifié ce que tu m'a dit mais il y a un autre code d'erreur : me disant que != n'est pas défini pour l'argument int, null. Voilà le code que j'ai modifié :
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
import cc.arduino.*; // reference the arduino library
Arduino arduino; // create a variable arduino of the Arduino data type
void setup () {
// set the window size:
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);
println(Serial.list()); // lister tous les ports série disponibles :
arduino = new Arduino(this, Arduino.list()[0], 57600);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
int inInt = arduino.analogRead(0) ;
if (inInt != null) {
// convert to an int and map to the screen height:
float inByte = float(inInt);
inByte = map(inByte, 0, 1023, 0, height);
// draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}Hors ligne
fdrg a écrit:
il faudrait donc en fait que j'établisse un rapport entre le signal électrique d'entré et un rythme de rotation. Par exemple entre 0 0.05v, un battement de 60, 0.10v, 70 etc. Puis pour chaque rythme une vitesse de rotation du globe adapté à Processing. Il y à du taf!!
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
fdrg a écrit:
Sinon pour le code du graphique j'ai modifié ce que tu m'a dit mais il y a un autre code d'erreur : me disant que != n'est pas défini pour l'argument int, null. Voilà le code que j'ai modifié :
Essaie d'enlever le test (if (inInt != null)), inutile maitenant que ce n'est plus une string
Hors ligne
Salut,
j'ai enlevé (if (inInt != null)) mais je me trouve avec une autre erreur : Error inside Serial.<init>()
j'ai donc modifié le code comme ceci :
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
import cc.arduino.*; // reference the arduino library
Arduino arduino; // create a variable arduino of the Arduino data type
void setup () {
// set the window size:
size(400, 300);
// set inital background:
background(0);
println(Serial.list()); // lister tous les ports série disponibles :
arduino = new Arduino(this, Arduino.list()[0], 57600);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
int inInt = arduino.analogRead(0) ;
{
// convert to an int and map to the screen height:
float inByte = float(inInt);
inByte = map(inByte, 0, 1023, 0, height);
// draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}Mais à ma grande déception il ne se passe rien dans le graphique. Là je suis franchement perdu.
Je continu de chercher par contre un moyen de récupérer et de pouvoir traiter le signal que m'envoie le cardio-fréquencemètre, voir d'utilisé un autre capteur.
Hors ligne
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
Je ne sais pas si l'erreur vient de là mais ça m'étonnerait que ça puisse fonctionner en l'état...
Hors ligne
J'ai bien enlevé les deux crochets mais le problème persiste.
Je vais donc tenter de reprendre mon code depuis le début et essayé de trouver l'erreur.
Hors ligne
Salut,
ca y est!!! voilà un code qui fonctionne!!! Du moins avec un potentiomètre. J'arrive donc à régler la vitesse de rotation du globe selon la position du potar. Voici le code :
// Basé sur le code Textured Sphere de Mike 'Flux' Chang et Toxi.
import processing.serial.*;
Serial myPort; // Créer l'objet de la classe série
float val; // Données reçu du port série
import cc.arduino.*; // reference the arduino library
Arduino arduino; // create a variable arduino of the Arduino data type
import processing.opengl.*;
PImage bg ;
PImage texmap;
float globeRadius = 450; // Détails des réglages des spheres
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, c, d;
int sDetail = 35;
float battement = 0;
float battementUpdated = 0;
void setup() {
size(1440, 800, OPENGL);
bg = loadImage("Shock Wave in Kepler's Supernova Remnant.png");
initializeSphere(sDetail);
texmap = loadImage("carte_monde.jpg");
initializeSphere(sDetail);
println(Serial.list()); // lister tous les ports série disponibles :
arduino = new Arduino(this, Arduino.list()[0], 57600);
}
void draw() {
background(0);
translate(width/2, height/2);
smooth();
specular(0, 0, 0);
noStroke();
float b = arduino.analogRead(0);
// rotation de l'univers
pushMatrix();
a += 0.02;
rotateY(a);
rotateX(1 / TWO_PI);
renderUniverse();
popMatrix();
// rotation du globe
pushMatrix();
rotateX(radians(-23)); // Angle de rotation de la Terre
rotateY(radians(-23));
rotateX(1/2*PI);
battementUpdated = b - battement; //
c += battementUpdated*0.0002;
d += c;
battement = b;
rotateY(d);
renderGlobe();
popMatrix();
println (b);
}
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];
// Calcul du cerle sur les plan X et Z
for (int i = 0; i < res; i++) {
cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH];
cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH];
}
// Le calcul vertexlist vertexlist commence au pôle sud
int vertCount = res * (res-1) + 2;
int currVert = 0;
// Reinitialisation des tableaux pour stocker les données des sommets
sphereX = new float[vertCount];
sphereY = new float[vertCount];
sphereZ = new float[vertCount];
float angle_step = (SINCOS_LENGTH*0.5f)/res;
float angle = angle_step;
// Etapes le long de l'axe Y
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;
}
// Dessiner la texture des spheres
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();
// Millieu de la boucle
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;
}
// Fermer chaque boucle
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;
// Ajouter la chape nord
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();
}Bon maintenant il me reste à trouver le moyen de faire fonctionner cela avec un capteur cardiaque...
Hors ligne