Go Down

Topic: Multiple layers using if-else  (Read 1 time) previous topic - next topic

Goldenshuttle

Say I have 4 switches controlling 2 servos,  can I use this block

if SW1==1 && SW2==0 && SW3=0 && SW4==0
{servo1.write(30);servo2.write(60);}
else if SW1==1 && SW2==1 && SW3=0 && SW4==0
{servo1.write(60);servo2.write(90);}
else if SW1==1 && SW2==1 && SW3=1 && SW4==0
{servo1.write(90);servo2.write(120);}
else if SW1==1 && SW2==1 && SW3=1 && SW4==1
{servo1.write(120);servo2.write(150);}


if the answer is yes, how many layers of  if-else one can use? is there a limit ?
Live to learn & make

Go Up