In our previous experiment , we have learned how to use Micro:bit to control 2 LEDs and make them twinkle alternatively. This time we are going to use a button to control LED flash. That means when we press down the button,the 2 LEDs flash in turns; when release the button, the LEDs stop flashing.
1.Set pin P2 to the high potential in the bricks of “on start”.
2.Read the status from P2 to check if the button is pressed, if yes, digital write signal 0 to P0 port to turn off the LED; digital write signal 1 to P1 port to turn on the LED, then set the pause in 500ms; digital write signal 1 to P0 port to turn on the LED; digital write signal 0 to P1 port to turn off the LED, then set the pause in 500ms.