This commit is contained in:
Kilian DECLERCQ 2022-04-07 10:36:29 +02:00
parent e0c946bcf1
commit 1ae439eb40
1 changed files with 40 additions and 0 deletions

40
roomba/roomba.ino Normal file
View File

@ -0,0 +1,40 @@
#include "MeMCore.h"
const int Port_1 =9;
const int Port_2 =10;
MeDCMotor motor1(Port_1);
MeDCMotor motor2(Port_2);
MeUltrasonicSensor ultraSensor(PORT_3); /* Ultrasonic module can ONLY be connected to port 3, 4, 6, 7, 8 of base shield. */
uint8_t motorSpeed =100;
double distance;
double threshold= 10;
int ran;
void setup()
{Serial.begin(9600);
}
void loop()
{
distance = ultraSensor.distanceCm();
if (distance <= threshold){
motor1.stop();
motor2.stop();
motorSpeed =random(-255,255);
Serial.println(motorSpeed);
motor1.run(motorSpeed); /* value: between -255 and 255. */
motor2.run(motorSpeed); /* value: between -255 and 255. */
delay(random(250,500));
}
else if (distance > threshold){
motor1.run(-200); /* value: between -255 and 255. */
motor2.run(200); /* value: between -255 and 255. */
}
}