Type Here to Get Search Results !

How To Use Control Statement Switch Function In Arduino Programming

The switch statement is more complicated version of the if statement as it can execute one or more blocks of code, depending on a range of conditions, probably we will use that in more complex programs. So, "if" statement allows us to choose between two options, true or false when there are more than two options, we can use multiple if statements or we can use the "switch" statement.



Switch allows us to choose between several option the basic syntax of the switch statement is as follow:


  1. Meaning we have the switch expression and then list of cases constant cases, 1,2, 3 and more.
  2. The number of cases can use can be as many as we need but each one should have a unique constant value.
  3. This is a simple example where we test the condition of some integer variable called “powerlevel”, in case the power level is equal to 1 than switch on only one led, in case the power level is equal to 2 than switch on two leds and so on...
  4. Now if there is no match with some constant expression.


For better understanding, please watch this video below.


Post a Comment

0 Comments