diff --git a/roomba/roomba.ino b/roomba/roomba.ino new file mode 100644 index 0000000..002d9ef --- /dev/null +++ b/roomba/roomba.ino @@ -0,0 +1,47 @@ +#include + + +MeUltrasonicSensor sensor(3); + +MeDCMotor leftRotor(9); +MeDCMotor rightRotor(10); + +float distance; + +float lSpeed; +float rSpeed; +float duration; +int Side; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + leftRotor.run(0); + rightRotor.run(0); + lSpeed = -200.0; + rSpeed = 200.0; +} + +void loop() { + // put your main code here, to run repeatedly: + distance = sensor.distanceCm(); + duration = random(1000); + if (distance>15.0){ + leftRotor.run(lSpeed); + rightRotor.run(rSpeed); + } + else{ + Side = random(2); + if (Side == 0){ + leftRotor.run(lSpeed); + rightRotor.run(-rSpeed); + } + if (Side == 1){ + leftRotor.run(-lSpeed); + rightRotor.run(rSpeed); + } + delay(duration); + } + + +} \ No newline at end of file