Kindly explain code line inside if statement
Title
Question
analogWrite(fwdbuttonState == LOW ? ICpin2 : ICpin7, motorValue);
digitalWrite(fwdbuttonState == LOW ? ICpin7 : ICpin2, motorValue);
kindly give explanation for these two lines, how can we change directions we have not used bckbuttonState variable.
Arduino Pulse-Width-Modulation 08-09 min 30-40 sec
Answers:
The if statement includes an OR condition, where it compares if either of fwdbuttonState or bckbuttonState is LOW.
Since we have used potentiometer to vary the speed of the motor, we used the analogWrite command, as this command changes the value depending on the duty cycle we provide. It is required to use the analogWrite command in one of the two above mentioned line of codes. So depending on which button is pressed, the code gets executed.
Login to add comment