user54542: How can I make the code of this project where I will press one time a button,  to turn on the first led (and turn off second led) and when other one press to turn on second led (and turn off the first led).

user8033: You can do this by keeping the 'state' saved in a variable.
Depending on it's state, the button will have a different effect.
After this effect, the state is updated, so that next iteration it will behave according to the other state.
state = led1
if(buttonpressed){
   if(state == led2){
     led1On();
     led2Off();
     state = led1;
   }else{
     led1Off();
     led2On();
     state = led2;
   }
}


54542: <p>How can I make the code of this project where I will press one time a button,  to turn on the first led (and turn off second led) and when other one press to turn on second led (and turn off the first led).</p>
 8033: <p>You can do this by keeping the 'state' saved in a variable.
Depending on it's <a href="https://en.wikipedia.org/wiki/Finite-state_machine" rel="nofollow noreferrer">state</a>, the button will have a different effect.</p>

<p>After this effect, the state is updated, so that next iteration it will behave according to the other state.</p>

<pre><code>state = led1
if(buttonpressed){
   if(state == led2){
     led1On();
     led2Off();
     state = led1;
   }else{
     led1Off();
     led2On();
     state = led2;
   }
}
</code></pre>
