Compare commits

...

2 Commits

Author SHA1 Message Date
Laure BEL 409834a830 Merge branch 'develop' 2024-03-11 11:50:38 +01:00
Laure BEL 2e1865d646 function control for a scare 2024-03-11 11:49:19 +01:00
1 changed files with 56 additions and 0 deletions

56
control/control.ino Normal file
View File

@ -0,0 +1,56 @@
#include "Arduino.h"
#include "Wire.h"
#include "MeMCore.h"
#include "SoftwareSerial.h"
MeDCMotor _leftMotor(9);
MeDCMotor _rightMotor(10);
MeUltrasonicSensor ultrasonicSensor(PORT_3);
MeGyro gyro;
double dis;
double ang;
double oldAng;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
gyro.begin();
_leftMotor.run(0);
_rightMotor.run(0);
}
void loop() {
// put your main code here, to run repeatedly:
for (int i=0; i!=4 ;i++){
dis=ultrasonicSensor.distanceCm();
while (ultrasonicSensor.distanceCm()>dis-30){
_leftMotor.run(-100);
_rightMotor.run(100);
//Serial.println(ultrasonicSensor.distanceCm());
}
_leftMotor.stop();
_rightMotor.stop();
delay(1000);
ang=gyro.getAngleZ();
oldAng=gyro.getAngleZ();
while (abs(ang-gyro.getAngleZ())<90){
_leftMotor.run(-100);
_rightMotor.run(-100);
gyro.update();
oldAng=gyro.getAngleZ();
}
_leftMotor.stop();
_rightMotor.stop();
delay(1000);
}
delay(5000);
}