Adding romba file with the code that makes the robot change direction in front of a obstacle.

This commit is contained in:
Mattis ROELLINGER 2024-03-11 09:53:40 +01:00
parent cab354ec78
commit 21fdaaf28c
1 changed files with 35 additions and 0 deletions

35
romba/romba.ino Normal file
View File

@ -0,0 +1,35 @@
#include "MeMCore.h"
#include "Arduino.h"
#include "Wire.h"
#include "SoftwareSerial.h"
MeDCMotor _leftMotor(9);
MeDCMotor _rightMotor(10);
MeUltrasonicSensor ultraSensor(PORT_3);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
if (ultraSensor.distanceCm()<20){
int x=random(-360,360);
_leftMotor.run(x);
_rightMotor.run(x);
delay(500);
}
else{
_leftMotor.run(200);
_rightMotor.run(-200);
}
// put your main code here, to run repeatedly:
}