From efd84a62861b94e098b5c15d32b675ddd8b5a82f Mon Sep 17 00:00:00 2001 From: laure Date: Mon, 11 Mar 2024 09:33:18 +0100 Subject: [PATCH] roomba function --- roomba/roomba.ino | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 roomba/roomba.ino diff --git a/roomba/roomba.ino b/roomba/roomba.ino new file mode 100644 index 0000000..10f7109 --- /dev/null +++ b/roomba/roomba.ino @@ -0,0 +1,34 @@ +#include "Arduino.h" +#include "Wire.h" +#include "MeMCore.h" +#include "SoftwareSerial.h" + +MeDCMotor _leftMotor(9); +MeDCMotor _rightMotor(10); +MeUltrasonicSensor ultrasonicSensor(PORT_3); + +void setup() { + // put your setup code here, to run once: + _leftMotor.run(0); + _rightMotor.run(0); + Serial.begin(9600); + +} + +void loop() { + // put your main code here, to run repeatedly: + if (ultrasonicSensor.distanceCm()>= 20){ + Serial.println(ultrasonicSensor.distanceCm()); + _leftMotor.run(-100); + _rightMotor.run(100); + }else{ + _leftMotor.stop(); + _rightMotor.stop(); + delay(1000); + _leftMotor.run(100); + _rightMotor.run(100); + delay(1000); + } + + +}