I have an arduino code for the line following car robot with CCD camera. However, I want to know what
if ((tt++) % 10 < 5) is actually meaning. I am a beginner with the programming. can you explain it?? thanks.
void loop() {
if ((tt++) % 10 < 5) <<<<<<<<<<<<<<<<<------------------------- <<Here what is the meaning of this part??>>
{
mainPage(1); mainPage(2); mainPage(3); mainPage(4); mainPage(5); mainPage(6);
}
motorMOVE(FW, 130, 130);
Chk_speedX(&speedL, &speedR);
// tracking algoritm
tracking_algoritm();
Cam_plot(0); // clear
getCameraZ(); // get data
Cam_plot(1); // plot
if (digitalRead(PC13))
digitalWrite(PC13, LOW);
else
digitalWrite(PC13, HIGH);
XXtime = millis() - XXtime;
Hello,
To explain more about the line I will first tell you about the IF clause. The IF clause lets you check a condition and if the condition is true then the commands written in the IF block will be executed. In the case, if the condition stands FALSE then the control will move further to check if there is else block or not. If else block is present it will be executed otherwise the control will move forward.
In this particular question the condition inside IF clause check for "(tt++) % 10 < 5". Now the value of tt will be increased by 1, now the new value of tt will be divided by 10 and the remainder will be compared with 5.
Let's say that tt=43
so tt++ = 44
now, 44 % 10. This % symbol is called mod which returns the remainder.
so 44%10 = 4
and 4<5
so the condition stands true and commands written in the block will be executed.
I hope I was able to answer your question.
Get Answers For Free
Most questions answered within 1 hours.