What am I missing? I attempted to start using routines in my programming but I am obviously not quite there. I have 2 programs that from what I understand do the same thing but the one using routines doesnt do anything.
First program:
int motorSpeed = 200; // motor speed
// Motor Pins
int motor1_Pin0 = 11;
int motor1_Pin1 = 6;
int motor2_Pin0 = 5;
int motor2_Pin1 = 3;
// Switch Pin
int bump1_Pin = 2;
int bump2_Pin = 7;
int leftval = 0;
int rightval = 0;
// - - - - - - - - - - - - - - - - - - - SETUP
void setup() {
// set Arduino pins as outputs
pinMode(motor1_Pin0, OUTPUT);
pinMode(motor1_Pin1, OUTPUT);
pinMode(motor2_Pin0, OUTPUT);
pinMode(motor2_Pin1, OUTPUT);
pinMode(bump1_Pin,INPUT); //Bumper switch pins as Inputs
pinMode(bump2_Pin, INPUT);
delay(500);
}
// - - - - - - - - - - - - - - - - - - - - LOOP
void loop() {
leftval = digitalRead(bump1_Pin);
rightval = digitalRead(bump2_Pin);
if (leftval == rightval){
analogWrite(motor1_Pin0, motorSpeed); //All Forward
digitalWrite(motor1_Pin1, LOW);
analogWrite(motor2_Pin0, motorSpeed);
digitalWrite(motor2_Pin1, LOW); //All Forwards end
}else if (leftval > rightval) {
digitalWrite(motor1_Pin0, LOW); //All Backwards
analogWrite(motor1_Pin1, motorSpeed);
digitalWrite(motor2_Pin0, LOW);
analogWrite(motor2_Pin1, motorSpeed); //All Backwards end
delay(2000);
digitalWrite(motor1_Pin0, motorSpeed); //Turn
analogWrite(motor1_Pin1, LOW);
digitalWrite(motor2_Pin0, LOW);
analogWrite(motor2_Pin1, motorSpeed); //End Turn
delay(1000);
}else if (rightval > leftval){
digitalWrite(motor1_Pin0, LOW); //Backwards
analogWrite(motor1_Pin1, motorSpeed);
digitalWrite(motor2_Pin0, LOW);
analogWrite(motor2_Pin1, motorSpeed);
delay(2000);
digitalWrite(motor1_Pin0, LOW); //Turn other way
analogWrite(motor1_Pin1, motorSpeed);
digitalWrite(motor2_Pin0, motorSpeed);
analogWrite(motor2_Pin1, LOW);
delay(1000);
}
}
So basically all I did was use the above code except after my void Setup() I attempted to create routines such as
AllForward() {
analogWrite(motor1_Pin0, motorSpeed); //All Forward
digitalWrite(motor1_Pin1, LOW);
analogWrite(motor2_Pin0, motorSpeed);
digitalWrite(motor2_Pin1, LOW); //All Forward end
}
and use that in my code i.e.
if(leftval==rightval){
AllForward()
}
I uploaded and my bot didnt move at all...What am I missing?