Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RedBot.h> //includes the redbot library
- RedBotMotors motors;// Instantiate the motor control object.
- RedBotSensor IRSensor1 = RedBotSensor(A4);// initialize sensors - left IR
- RedBotSensor IRSensor2 = RedBotSensor(A5);// right IR
- RedBotBumper lBumper = RedBotBumper(3); // Left bumper
- RedBotBumper rBumper = RedBotBumper(11); //Right bumper
- int thr = 950; // wood floor varies more
- int lSpeed = -70; //forward speed
- int rSpeed = 55; //right speed significantly slowed so it can slowly curve right when moving forward.
- int lBumperState; //detect bumper touch
- int rBumperState; //detect bumper touch
- void setup() {
- //test code
- //motors.leftMotor(-80);
- //motors.rightMotor(75);
- //delay(6000);
- //motors.stop();
- //delay(100);
- //motors.leftMotor(-100);
- //motors.rightMotor(-100);
- //delay(520);
- //motors.stop();
- Serial.begin(9600);
- }
- void loop() {
- //test code
- ///Serial.print(IRSensor1.read());
- //Serial.print("\t");// tab character
- //Serial.print(IRSensor2.read());
- //Serial.print("\t");
- motors.leftMotor(lSpeed);
- motors.rightMotor(rSpeed);
- lBumperState = lBumper.read();
- rBumperState = rBumper.read();
- if(lBumperState == LOW && rBumperState == HIGH) { //Left bumper triggered, back up and turn left large.
- motors.stop();
- delay(250);
- motors.leftMotor(60);
- motors.rightMotor(-56);
- delay(1000);
- motors.stop();
- motors.leftMotor(60);
- motors.rightMotor(60);
- delay(700);
- motors.leftMotor(lSpeed);
- motors.rightMotor(rSpeed);
- }
- if(lBumperState == LOW && rBumperState == LOW) { //Left and right bumper triggered, back up and left large.
- motors.stop();
- delay(250);
- motors.leftMotor(60);
- motors.rightMotor(-56);
- delay(1000);
- motors.stop();
- delay(250);
- motors.leftMotor(60);
- motors.rightMotor(60);
- delay(600);
- motors.leftMotor(lSpeed);
- motors.rightMotor(rSpeed);
- }
- if(rBumperState == LOW && lBumperState == HIGH){ //Right bumper triggered, back up and turn left small
- motors.stop();
- motors.leftMotor(60);
- motors.rightMotor(-56);
- delay(500);
- motors.stop();
- delay(250);
- motors.leftMotor(60);
- motors.rightMotor(60);
- delay(400);
- motors.stop();
- motors.leftMotor(lSpeed);
- motors.rightMotor(rSpeed);
- }
- //test code
- //Serial.print(IRSensor1.read());
- //Serial.print("\t");// tab character
- //Serial.print(IRSensor2.read());
- //Serial.print("\t");
- }
Advertisement
Add Comment
Please, Sign In to add comment