Hey,
I'm making a line following robot that needs to drop a ping pong ball at the end of a track. I made a small change to my code then all of the sudden stuff isn't working. Here is my original code.
int buttonpin = 0; //Sets pin 0 to be called buttonpin.
int leftmotor = 10; //Sets pin 10 to control Left Motors.
int rightmotor = 11; //Sets ping 11 to control Right Motor
int leftline = 5; //Left line follower input.
int middleline = 4; //Middle line follower input.
int rightline = 3; //Right line follower input.
int bumper = 7; //Bumber swithch input
//add pins for for ping pong ball device.
void setup() {
pinMode(buttonpin, INPUT); //sets pin 0 as input.
pinMode(leftmotor, OUTPUT); //sets pin 10 as output.
pinMode(rightmotor, OUTPUT); //Sets pin 11 as output.
pinMode(leftline, INPUT); //Sets pin 5 as input.
pinMode(middleline, INPUT); //Sets pin 4 as input.
pinMode(rightline, INPUT); //Sets pin 3 as input.
pinMode(bumper, INPUT); //Sets pin 7 as input.
// configure pins yet to be added listed above.
}
void loop() {
// Main runtime instruction set.
// Read sensor input.
if (digitalRead(leftline) == HIGH) {
digitalWrite(leftmotor, HIGH); // Stops left motor.
digitalWrite(rightmotor, LOW); //Starts right motor
delay(1);
}
else {
//Do nothing
}
if (digitalRead(rightline) == HIGH) {
digitalWrite(leftmotor, LOW); // Runs left motor.
digitalWrite(rightmotor, HIGH); // Stops left motor.
delay(1);
}
else {
// Do nothing
}
if (digitalRead(middleline) == HIGH) {
digitalWrite(leftmotor, HIGH); //Runs left motor
digitalWrite(rightmotor, HIGH); //Runs right motor.
delay(1);
}
else {
//DO nothing
}
}
This code works fine. Then I made a change to add the motor which is supposed to be triggered by a bumper switch. I added it at the end but now my robot doesn't seem to follow a line and when the bumper is triggered it doesn't seem to spin the motor like it should. The code with the ball added that doesn't work is below
int buttonpin = 0; //Sets pin 0 to be called buttonpin.
int leftmotor = 10; //Sets pin 10 to control Left Motors.
int rightmotor = 11; //Sets ping 11 to control Right Motor
int leftline = 5; //Left line follower input.
int middleline = 4; //Middle line follower input.
int rightline = 3; //Right line follower input.
int bumper = 7; //Bumber swithch input
int ball = 9; //Ball motor
//add pins for for ping pong ball device.
void setup() {
pinMode(buttonpin, INPUT); //sets pin 0 as input.
pinMode(leftmotor, OUTPUT); //sets pin 10 as output.
pinMode(rightmotor, OUTPUT); //Sets pin 11 as output.
pinMode(leftline, INPUT); //Sets pin 5 as input.
pinMode(middleline, INPUT); //Sets pin 4 as input.
pinMode(rightline, INPUT); //Sets pin 3 as input.
pinMode(bumper, INPUT); //Sets pin 7 as input.
pinMode(ball, OUTPUT); // Sets pin 9 as output.
}
void loop() {
// Main runtime instruction set.
// Read sensor input.
if (digitalRead(leftline) == HIGH) {
digitalWrite(leftmotor, HIGH); // Stops left motor.
digitalWrite(rightmotor, LOW); //Starts right motor
delay(1);
}
else {
//Do nothing
}
if (digitalRead(rightline) == HIGH) {
digitalWrite(leftmotor, LOW); // Runs left motor.
digitalWrite(rightmotor, HIGH); // Stops left motor.
delay(1);
}
else {
// Do nothing
}
if (digitalRead(middleline) == HIGH) {
digitalWrite(leftmotor, HIGH); //Runs left motor
digitalWrite(rightmotor, HIGH); //Runs right motor.
delay(1);
}
else {
//DO nothing
}
if (digitalRead(bumper) == HIGH) {
digitalWrite(leftmotor, LOW); // stops left motor.
digitalWrite(rightmotor, LOW); // Stops right motor.
digitalWrite(ball, HIGH); //starts motor to release ball.
delay(425);
digitalWrite(ball,LOW);
delay(1000);
}
else {
// Do nothing
}
}
Any and all help is really appreciated.