Using firmware: MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit with nRF51822
Each of these, when observed on a logic analyser, produced an incorrect pattern. The read_digital() shortly before the write_digital() seemed to affect it.
Code: Select all
from microbit import *
clk=pin2
for i in range(16):
clk.write_digital(not clk.read_digital())
for i in range(16):
state = not clk.read_digital()
clk.write_digital(state)
for i in range(16):
state = clk.read_digital()
clk.write_digital(not state)
This one works as expected. I moved the read_digital() above and simply toggled the state boolean on each iteration.
Code: Select all
from microbit import *
clk=pin2
state = clk.read_digital()
for i in range(16):
state = not state
clk.write_digital(state)