Salut tout le monde!
J’ai tout repris à 0 et mon code est beaucoup plus propre et… ça marche!
Cependant il me reste un mini soucis à régler et je dois plus voir clair là mais je m’en sors pas et je suis à CA de terminer… ^^
Je cherche à envoyer des 1 et des 0 dans processing pour que le glitch soit initialisé quand il reçoit des 1.
Pour cela je prévois dans mon code arduino que lorsque le capteur de vibration n’est pas à 670 ou 671 (valeur au « repos ») et détecte donc du mouvement il m’envoie des 1, et des 0 si pas de vibrations.
Mais voilà, ça ne marche pas, il ne m’inscrit dans la console que les valeurs originales: 670,671,622…
Je ne vois pas trop où je me suis emmêlés les pieds, si quelqu’un peut jeter un œil frais dessus ce serait formidable!
Mille Merci
#include<Wire.h>
#include<stdio.h> //librairie pour utiliser le printf
const int MPU=0x68; // I2C address of the MPU-6050
int16_t GyX,GyY,GyZ;
int sensorValue1, sensorValue2, sensorValue3, sensorValue4;
int valVibrator=0;
int val=0;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,6,true); // request a total of 6 registers
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
val=analogRead(A0);
Serial.println(val);
if(val!=670 || val!=671){
valVibrator=1;
}
sensorValue1 = GyX/10; // read sensor in analog input 0
sensorValue2 = GyY/10; // read sensor in analog input 1
sensorValue3 = GyZ; // read sensor in analog input 2
sensorValue4 = valVibrator; // read sensor in analog input 3
Serial.print(sensorValue1, DEC); // print sensor 1
Serial.print(","); // print ','
Serial.print(sensorValue2, DEC); // print sensor 2
Serial.print(","); // print ','
Serial.print(sensorValue3, DEC); // print sensor 3
Serial.print(","); // print ','
Serial.println(valVibrator, DEC); // print sensor 4 and newline (println)
delay(200); // wait 200ms for next reading
valVibrator=0;
}
PROCESSING
import processing.serial.*;
import glitchP5.*; //import Glitch P5
////codearduino/////////////////////////////
Serial myPort;
int linefeed = 10; // Linefeed in ASCII
int numSensors = 4; // we will be expecting for reading data from four sensors
int sensors[]; // array to read the 4 values
int pSensors[]; // array to store the previuos reading, usefur for comparing
// actual reading with the last one
String portname="/dev/cu.usbmodem1421";
/////codedessin/////
GlitchP5 glitchP5; // declare an instance of GlitchP5. only one is needed
int j=0; //variable d'incrémentation carré dans carré
int max=1; //nombre d'itération, soit le nb de carrés dans le carré
int longueur=10; // longueur du carré
int largeur=10; //largeur du carré
float value=0; //variable pour la rotation
int mouseXold=displayWidth/2;
int mouseYold=displayHeight/2;
float bornexinf=0;
float bornexsup=0;
float borneyinf=0;
float borneysup=0;
void setup() {
size(displayWidth, displayHeight);
background (255);
smooth();
glitchP5 = new GlitchP5(this); // initiate the glitchP5 instance;
myPort = new Serial(this, portname, 9600);
// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil(linefeed);
}
void draw() {
glitchP5.run();
strokeWeight(1);
noFill();
stroke(random(255),random(255),random(255));
rectMode(CENTER);
if ((pSensors != null)&&(sensors != null)) {
for (int i=0; i < numSensors; i++) {
float f = sensors[i] - pSensors[i]; // actual - previous value
if (f > 0) {
println("sensor "+i+" increased by "+f); // value increased
}
if (f < 0) {
println("sensor "+i+" decreased by "+f); // value decreased
}
}
for(j=0;j<max;j++){
longueur=longueur+1;
largeur=largeur+1;
translate(width/2, height/2);
rotate(value);
translate(-width/2, -height/2);
rect(sensors[0],sensors[1],longueur,largeur);
redraw();
bornexinf=mouseXold-50;
bornexsup=mouseXold+50;
borneyinf=mouseYold-50;
borneysup=mouseYold+50;
if(bornexinf>sensors[0] || sensors[0]>bornexsup || borneyinf>sensors[1] || sensors[1]>borneysup){
longueur=5;
largeur=5;
}
mouseXold=sensors[0];
mouseYold=sensors[1];
if(sensors[3]==1)
{
// trigger a glitch: glitchP5.glitch( posX, //
// posY, // position on screen(int)
// posJitterX, //
// posJitterY, // max. position offset(int)
// sizeX, //
// sizeY, // size (int)
// numberOfGlitches, // number of individual glitches (int)
// randomness, // this is a jitter for size (float)
// attack, // max time (in frames) until indiv. glitch appears (int)
// sustain // max time until it dies off after appearing (int)
// );
glitchP5.glitch(sensors[0], sensors[1], 200, 400, 200, 60, 120, 10.0f, 20, 1);
}
}
}
}
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
pSensors = sensors;
sensors = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ":" + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
}
}