RPR Cleaning Program

This program allows RPR to "free roam". I wrote this program a number of years ago, and I have not thoroughly looked through it since. It is not an overly well written program, and it contains no comments. It drives forward until it hits a wall. Then it turns left or right based on which side of the bumper detected the impact. If it believes itself to be trapped in a corner, it will back out and turn around. It thinks it is trapped in a corner if it impacts a wall on both sides too many times in a given period of time. Instead of using a "BlinkWithoutDelay" like function, that period of time is measured by counting the number of cycles of a loop (which isn't particularly elegant, but it worked). The Tri-Bot IR remote can be used to modify the behaviour of RPR. The program buttons can be used to increased or decreased the amount of time it turns when it detects a wall. The direction buttons can be used to manually change RPR's direction.

#include<Servo.h>
#include <IRremote.h>

Servo rightW;
Servo leftW;
IRrecv irrecv(11);
decode_results results;

boolean leftSen = HIGH;
boolean rightSen = 0;
long Loop = 0;
short Rt = 0;
short Lt = 0;
int Delay = 200;
short blnk;

void setup() {
  irrecv.enableIRIn();

  rightW.attach(5);
  leftW.attach(3);

  pinMode(13, OUTPUT);
  pinMode(2, INPUT);
  pinMode(4, INPUT);
}


void loop() {
  if (irrecv.decode(&results)) {

    if (results.value == 0x11CAA87A) {
      Delay = Delay - 100;
      while (blnk < Delay / 100) {
        digitalWrite(13, HIGH);
        delay(150);
        digitalWrite(13, LOW);
        delay(150);
        blnk ++;
      }
    }

    if (results.value == 0xCBA47867) {
      Delay = Delay + 100;
      while (blnk < Delay / 100) {
        digitalWrite(13, HIGH);
        delay(150);
        digitalWrite(13, LOW);
        delay(150);
        blnk ++;
      }
    }


    if (results.value == 0x8C887520) {
      rightW.write(0);
      leftW.write(180);
      delay(1000);
    }

    if (results.value == 0xAC46B923) {
      rightW.write(0);
      leftW.write(0);
      delay(1000);
    }

    if (results.value == 0x97A6B383) {
      rightW.write(180);
      leftW.write(180);
      delay(1000);
    }

    irrecv.resume();
  }

  rightW.write(180);
  leftW.write(0);

  leftSen = digitalRead(2);
  rightSen = digitalRead(4);

  Loop++;
  delay(2);

  if (leftSen == HIGH) {

    rightW.write(0);
    leftW.write(180);
    delay(Delay);
    leftW.write(0);
    delay(Delay);
    Lt ++;
  }

  else if (rightSen == HIGH) {

    leftW.write(180);
    rightW.write(0);
    delay(Delay);
    rightW.write(180);
    delay(Delay);
    Rt ++;
  }

  if (Loop > 3200) {
    Rt = 0;
    Lt = 0;
    Loop = 0;
  }

  if (Rt > 1 && Lt > 1) {
    rightW.write(0);
    leftW.write(180);
    delay(1500);
    rightW.write(180);
    Rt = 0;
    Lt = 0;
    delay(150);
  }
  blnk = 0;
}