True and False conditions In Arduino

In a programming language, we will learn about the commands associated with the condition (logic) True and False. The commands are associated with logic that is commonly used for example IF and IF-ELSE and WHILE we have learned before.

In theory, True and False means means 1 0. In this programming, False condition is always 0, but not always 1. True True condition is other than 0, remember other than zero (0) will be considered True. Consider the code below:

while(1){
digitalWrite(pinLED, HIGH); delay(100); digitalWrite(pinLED, LOW); 
delay(100);
}

 

The above program will run forever (looping forever) for Arduino has not been reset or electricity is not disconnected. Why? Because 1 means True. Literally, the line while (1) can be interpreted "as long as is true, then the execution of this code".

Remember, writing logical operators "equals" not only use the equal sign "=", but using two equal "==". If you only use the "=", then the question is not to logic, but for the carriers determination of variable content (assignment). Correct writing is:

while( timeDelay == 1000 ){
//
}

if( timeDelay == 0){
//
}


 

instead,
while( timeDelay = 1000 ){   //writing WRONG!
//
}

if( timeDelay = 0 ){  // writing WRONG!
//
}
 

Subscribe to receive free email updates:

0 Response to "True and False conditions In Arduino"

Post a Comment