bonjour,
il y a assez de truc sur le net pour ca quand même.
bon c'est vendredi, suis malade, donc ma bonté va prendre le dessus.
un truc que j'ai commencé a faire pour mettre de niveau mon télescope astro, hé oui suis un gros fénéant parfois.
il n'y a qu'un seul moteur dans le code, mais a toi de te démerd.... ![]()
le but étant d'avoir une mise à niveau automatique avec rattrapage
#include <MPU6050.h>
#include <I2Cdev.h>
#include "Wire.h"
#include <AFMotor.h>
// Connect a stepper motor with 48 steps per revolution (7.5 degree)
// to motor port #2 (M3 and M4)
AF_Stepper motor(200, 2);
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
MPU6050 accelgyro;
int val;
int prevVal;
#define LED_PIN 13
void setup()
{
Wire.begin();
Serial.begin(115200);
Serial.println("Initialize MPU");
mpu.initialize();
Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");
motor.setSpeed(50); // 10 rpm
pinMode(LED_PIN, OUTPUT);
}
void loop()
{
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
ax = map(ax, -32767, 32767, -255, 255);
ay = map(ay, -32767, 32767, -255, 255);
az = map(az, -32767, 32767, -255, 255);
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.print(gz); Serial.print("\t\n");
if (ay < -1) motor.step(1, BACKWARD, SINGLE);
if (ay > 1) motor.step(1, FORWARD, SINGLE);
if( ay >= -1 && ay <= 1){digitalWrite(LED_PIN, HIGH);}else{digitalWrite(LED_PIN, LOW);}
delay(100);
}