I'm building a small car as my first project and its pretty simple. I have a gear box with two DC motors and I have each of those motors controlled by two push buttons. It isn't wireless or anything, just a simple little car. The way it is right now, I can control each motor individually. But when I tried to make it so that when I press both buttons both motors spin, only one of the motors will spin.
Here is my code maybe you can tell me what I am doing wrong. Be gentle this is the first script I've written myself. Sorry for lack of comments.
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
int sensorValueone = digitalRead(2);
int sensorValuetwo = digitalRead(3);
if (sensorValueone == 1){
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
}
else if (sensorValuetwo == 1) {
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
}
else if ((sensorValueone && sensorValuetwo) == 1){ // this is the where I believe the problem to be
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
else{
digitalWrite(12, LOW);
digitalWrite(11, LOW);
}
}