From 21fdaaf28c49b4209b3fd44ebc1ec384e47aa16a Mon Sep 17 00:00:00 2001 From: "mattis.roellinger" Date: Mon, 11 Mar 2024 09:53:40 +0100 Subject: [PATCH] Adding romba file with the code that makes the robot change direction in front of a obstacle. --- romba/romba.ino | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 romba/romba.ino diff --git a/romba/romba.ino b/romba/romba.ino new file mode 100644 index 0000000..2013f02 --- /dev/null +++ b/romba/romba.ino @@ -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: + +}