Hello I was wondering how could i fix this code because it is just starting and not waiting for me to start it with the push button I need some help i am new to this to any tips would help.
int enA = 9;
int in1 = 8;
int in2 = 7;
int enB = 3;
int in3 = 5;
int in4 = 4;
int pushbutton = 2;
bool CarIsRunning = 0;
void setup() {
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(pushbutton, INPUT);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
void loop() {
if (CarIsRunning){
digitalWrite(enA, HIGH);
digitalWrite(enB,HIGH);
}
if (CarIsRunning){
digitalWrite(enA, HIGH);
digitalWrite(enB,HIGH);
}
int buttonVal = digitalRead(pushbutton);
if (buttonVal = 1){
digitalWrite(enA, HIGH);
digitalWrite(enB,HIGH);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
}
}
buttons are typically connected between the pin and ground, the pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.
a button press can be recognized by detecting a change in state and becoming LOW