Voici mon code pour l'instant :
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "math.h"
#include <IRremote.h>
IRsend irsend;
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az; //mesures brutes
int16_t gx, gy, gz;
float anglex = 0;
float angley = 0;
float offsetx = 0;
float offsety = 0;
float xmax = 0;
float xmin = 0;
float ymax = 0;
float ymin = 0;
byte delta = 2;
byte l = 0;
int khz = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int VolUp[51] = {3850, 4050, 400, 2050, 400, 2050, 400, 2050, 400, 2000, 450, 1100, 400, 1100, 400, 2050, 400, 1100, 400, 2050, 400, 2050, 400, 2050, 400, 2050, 400, 1100, 400, 1100, 400, 1100, 450, 1100, 400, 2050, 400, 2050, 400, 1100, 400, 2050, 400, 1100, 400, 1100, 400, 1100, 450, 1050, 450};
unsigned int VolDown[51] = {3900, 4000, 450, 2000, 450, 2000, 450, 2000, 450, 2000, 450, 1050, 450, 1050, 500, 1950, 450, 1050, 500, 1950, 500, 1950, 450, 2000, 450, 1050, 450, 1100, 400, 1100, 450, 1050, 450, 1050, 450, 2000, 450, 2000, 450, 1050, 450, 2000, 450, 1050, 450, 1100, 450, 1050, 450, 2000, 450};
unsigned int ProgUp[51] = {3850, 4050, 400, 2050, 400, 2050, 400, 2050, 400, 2050, 400, 1100, 400, 1100, 400, 2050, 400, 1100, 400, 2050, 400, 2050, 400, 1100, 400, 2050, 400, 1100, 450, 1100, 400, 1100, 400, 1100, 400, 2050, 400, 2050, 400, 1100, 400, 2050, 400, 1100, 400, 1100, 450, 2000, 450, 1100, 400};
unsigned int ProgDown[51] = {3900, 4000, 450, 2000, 450, 1950, 500, 1950, 500, 1950, 500, 1050, 450, 1050, 450, 2000, 450, 1050, 450, 2000, 450, 2000, 450, 1050, 450, 1050, 500, 1000, 500, 1050, 450, 1050, 450, 1050, 450, 2000, 450, 2000, 450, 1050, 450, 2000, 450, 1050, 450, 1050, 450, 2000, 500, 1950, 500};
float calculAngle () {
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
anglex = 0.98 * (anglex + float(gx) * 0.01 / 131) + 0.02 * atan2((double)ay, (double)az) * 180 / PI;
angley = 0.98 * (angley + float(gy) * 0.01 / 131) + 0.02 * atan2((double)ax, (double)az) * 180 / PI;
delay(10);
}
void setup() {
Wire.begin(); //I2C bus
Serial.begin(115200);
pinMode (A3, OUTPUT);
// initialize device
Serial.println("Initialisation I2C...");
accelgyro.initialize();
// verify connection
Serial.println("Test de la connection du dispositif ...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection reussie" : "MPU6050 connection echec");
delay(1000);
for (int i = 0; i < 350; i++) calculAngle ();
offsetx = anglex;
offsety = angley;
}
void loop() {
calculAngle ();
if (anglex - offsetx < -30) { // Volume Down
if (anglex - offsetx < xmin) xmin = anglex - offsetx;
if (anglex - offsetx < xmin + delta) {
digitalWrite(A3, HIGH);
l = sizeof(VolDown) / sizeof(VolDown[0]);
irsend.sendRaw(VolDown, l, khz);
Serial.print ("Vol Down, ");
delay(500);
}
}
else if (anglex - offsetx > 30) { // Volume Up
if (anglex - offsetx > xmax) xmax = anglex - offsetx;
if (anglex - offsetx > xmax - delta) {
digitalWrite(A3, HIGH);
l = sizeof(VolUp) / sizeof(VolUp[0]);
irsend.sendRaw(VolUp, l, khz);
Serial.print ("Vol Up, ");
delay(500);
}
}
else {
digitalWrite(A3, LOW);
xmin = 0;
xmax = 0;
}
if (angley - offsety < -30) { // Program Up
if (angley - offsety < ymin) ymin = angley - offsety;
if (angley - offsety < ymin + delta) {
digitalWrite(A3, HIGH);
l = sizeof(ProgUp) / sizeof(ProgUp[0]);
irsend.sendRaw(ProgUp, l, khz);
Serial.print ("Prog Up, ");
delay(500);
}
}
else if (angley - offsety > 30) { // Program Down
if (angley - offsety > ymax) ymax = angley - offsety;
if (angley - offsety > ymax - delta) {
digitalWrite(A3, HIGH);
l = sizeof(ProgDown) / sizeof(ProgDown[0]);
irsend.sendRaw(ProgDown, l, khz);
Serial.print ("Prog Down, ");
delay(500);
}
}
else {
digitalWrite(A3, LOW);
ymin = 0;
ymax = 0;
}
Serial.print(anglex - offsetx);
Serial.print(",");
Serial.println(angley - offsety);
}
Bien sûr tu n'as pas besoin de toute la partie IR : le include IRRemote, tous les isrsend, les tableaux...