How the led_blink_2x Script Works
These statements repeat indefinitely inside the while True loop:
- The pin13.write_digital(1) method call sets a high signal through P13, turning on the green light.
- The pin14.write_digital(1) call does the same thing but through P14, turning on the yellow light.
- The sleep(500) call makes the script pause for 0.5 s. The lights stay on during this time.
- The pin13.write_digital(0) and pin14_write_digital(0) calls set P13 and P14 low, turning the LED lights off.
- The sleep(500) call makes the script pause for another 0.5 s, during which time, the lights stay off.
Try This: On/Off Alternating
Changing from simultaneous to alternating blinks is pretty simple. All you have to do is change the state argument in two of the pin14.write_digital calls.
- Change the line 1 comment and the project name field to led_blink_2x_alternating.
- Change the first pin14.write_digital call’s state argument from 1 to 0.
- Change the second pin14.write_digital call’s state argument from 0 to1.
- Click Save and then click Send to micro:bit.
- Verify that only one light is on at a time, and that they alternate.