int PWMA = 5; //PIN Motor A = Speed
int PWMB = 6; //PIN Motor B = Speed
int BIN_1 = 7; //PIN Motor B = Spin
int AIN_1 = 8; //PIN Motor A = Spin
int STBY = 3; //Motor Standby
int Speed = 100;
void setup(){
// put your setup code here, to run once:
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(AIN_1, OUTPUT);
pinMode(BIN_1, OUTPUT);
pinMode(STBY, OUTPUT);
digitalWrite(STBY, HIGH);
}
void loop(){
forward();
backward();
while (true){};
}
//while (true){} //goes backwards for ever
//while(true){digitalWrite(STBY, LOW);} //Only way to get the car to stop
// seems if there isn't an argument within in the curly brackets it just fills it with what ran before it
void forward(){
analogWrite(PWMA, Speed);
digitalWrite(PWMB, Speed);
digitalWrite(AIN_1, HIGH);
digitalWrite(BIN_1, HIGH);
delay(1000);
}
void backward(){
analogWrite(PWMA, Speed);
analogWrite(PWMB, Speed);
digitalWrite(AIN_1, LOW);
digitalWrite(BIN_1, LOW);
delay(1000);
}
void left(){
analogWrite(PWMA, Speed);
analogWrite(PWMB, Speed);
digitalWrite(AIN_1, LOW);
digitalWrite(BIN_1, HIGH);
delay(250);
}
void right(){
analogWrite(PWMA, Speed);
analogWrite(PWMB, Speed);
digitalWrite(AIN_1, HIGH);
digitalWrite(BIN_1, LOW);
delay(250);
}
void stopCar(){
analogWrite(PWMA, 0);
analogWrite(PWMB, 0);
digitalWrite(AIN_1, LOW);
digitalWrite(BIN_1, LOW);
}
I am very new to programming. I only got this Elegoo robot car version 4, so I can practice my coding. I wanted to know if anyone can help me with this problem I am having.
I want to know why the while loop replaces its empty curly brackets with the code on top if no condition was written inside it. From what I have read about the while loop should not work like that, it should run what's in the curly brackets. So if it has nothing it shouldn't constantly run nothing.