Bonjour, étant élève en STI2D, nous travaillons sur une plateforme mobile qui pourrait tondre la pelouse
Nous sommes confronté à un problème. Nous n'arrivons pas à régler le temps pour les fonctions avance recule droite gauche.
Nous essayons de faire tourner on rond juste la tondeuse.
Merci à ceux qui m'aideront. Voici le code
#include <SoftwareSerial.h>
#include <Wire.h>
#define CMD 0x10
// This is a but with arduino 1
#define MD25ADDRESS 0x58 // Address of the MD25
#define SOFTWAREREG 0x0D // Byte to read the software version, Values of 0 eing sent using write have to be cast as a byte to stop them being misinterperted as NULL
#define SPEED1 (byte)0x00 // Byte to send speed to first motor
#define SPEED2 0x01 // Byte to send speed to second motor
int x=0;
int y =3000;
int z =1672;
void setup(){
Wire.begin(); // Démarrer la liaison série
delay(100); // attendre 1 milli seconde
}
void loop(){
x = 165
; //on rentre la valeur pour la puissance des moteurs
{ // Start loop to drive motors reverse
stopMotor();
avance ();
// Calls function that reads and displays battery volts
}
}
void avance (){
Wire.beginTransmission(MD25ADDRESS); // Drive motor 2 at speed value stored in x
Wire.write(SPEED2);
Wire.write(x);
Wire.endTransmission();
Wire.beginTransmission(MD25ADDRESS); // Drive motor 1 at speed value stored in x
Wire.write(SPEED1);
Wire.write(x);
Wire.endTransmission();
delay(y);
}
void stopMotor(){ // Function to stop motors
Wire.beginTransmission(MD25ADDRESS);
Wire.write(SPEED2);
Wire.write(128); // Sends a value of 128 to motor 2 this value stops the motor
Wire.endTransmission();
Wire.beginTransmission(MD25ADDRESS);
Wire.write(SPEED1);
Wire.write(128);
Wire.endTransmission();
delay (1);
}
void right () {
Wire.beginTransmission(MD25ADDRESS);
Wire.write(SPEED2);
Wire.write(133); // Sends a value of 128 to motor 2 this value stops the motor
Wire.endTransmission();
Wire.beginTransmission(MD25ADDRESS);
Wire.write(SPEED1);
Wire.write(x);
Wire.endTransmission();
delay(z);
}
void left () {
Wire.beginTransmission(MD25ADDRESS);
Wire.write(SPEED2);
Wire.write(x); // Sends a value of 128 to motor 2 this value stops the motor
Wire.endTransmission();
Wire.beginTransmission(MD25ADDRESS);
Wire.write(SPEED1);
Wire.write(128);
Wire.endTransmission();
}