This commit is contained in:
theyatokami 2023-04-24 09:21:43 +02:00
parent 35916ee367
commit 0df930ede7
2 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,44 @@
#include <MeMCore.h>
// The two motor objects
MeDCMotor motor1(9);
MeDCMotor motor2(10);
uint8_t Lspeed = 100;
uint8_t Rspeed = 100;
void setup()
{
}
void loop()
{
devant();
delay(1000);
stop();
delay(100);
turnleft();
delay(1000);
}
void turnright(){
motor1.run(Lspeed);
motor2.run(Rspeed);
}
void turnleft(){
motor1.run(-Lspeed);
motor2.run(-Rspeed);
}
void devant(){
motor1.run(-Lspeed);
motor2.run(Rspeed);
}
void derriere(){
motor1.run(Lspeed);
motor2.run(-Rspeed);
}
void stop(){
motor1.run(0);
motor2.run(0);
}

View File

@ -0,0 +1,46 @@
#include <MeMCore.h>
#include <MeUltrasonicSensor.h>
// The two motor objects
MeDCMotor motor1(9);
MeDCMotor motor2(10);
MeUltrasonicSensor sensor1(3);
uint8_t Lspeed = 200;
uint8_t Rspeed = 200;
void setup()
{
Serial.begin(9600);
}
void loop()
{
devant();
int distance = sensor1.distanceCm();
Serial.println(distance);
if (distance < 20){
turnright();
delay(600);
}
}
void turnright(){
motor1.run(Lspeed);
motor2.run(Rspeed);
}
void turnleft(){
motor1.run(-Lspeed);
motor2.run(-Rspeed);
}
void devant(){
motor1.run(-Lspeed);
motor2.run(Rspeed);
}
void derriere(){
motor1.run(Lspeed);
motor2.run(-Rspeed);
}
void stop(){
motor1.run(0);
motor2.run(0);
}