Ive just added some bump sensors to my bot, simple switches. I have added them to interrupt pins so that the bot CANT drive into stuff. (i cant forget to include monitoring the bumps to every section of code)
Now i realise that one should always include ALL the code when posting to a forum asking for help, but there is an awful lot of it at the moment, so first i shall include the interrupt bit i have added this evening.
So i have added the connections for each bumper before the Setup.
const int RBump = 3;
const int LBump = 2;
Then in the VoidSetup,
pinMode (LBump,INPUT_PULLUP); (I want to use the internal Pullups, perhaps this is an issue?):
pinMode (RBump,INPUT_PULLUP);
attachInterrupt(0, BumpL, LOW);
attachInterrupt(1, BumpR, LOW);
void BumpL(){ motorL.run(BACKWARD); motorR.run(BACKWARD); digitalWrite(LLED, LOW); digitalWrite(RLED, LOW); Hori.write(60); Vert.write(90); delay(500); motorL.run(RELEASE); motorR.run(RELEASE);Ping();
int LeftDist = distance;
int LeftLight = analogRead(PR);
Hori.write(120);
Vert.write(90);
delay(500);
Ping();
int RightDist = distance;
int RightLight = analogRead(PR);
Hori.write(90);
delay(1000);
if (LeftDist < RightDist) {
motorL.run(RELEASE);
motorR.run(BACKWARD);
digitalWrite(LLED, LOW);
digitalWrite(RLED, HIGH);
delay (500);
motorL.run(RELEASE);
motorR.run(RELEASE);
digitalWrite(LLED, LOW);
digitalWrite(RLED, LOW);
}else {
Obstacle();
}
}