Micropython Guide

From ElectroDragon Wiki

Operations

Plug In

  • You will get a portable disk "TPYBFLASH", size 100KB
  • Include files:
boot.py -> no need change
main.py -> board main python script
README.txt
tpybcdc.inf -> Board USB shell driver
  • Drag new main.py file to update code

Note

  • Only restart or re-power after the files is fully copied, the on board status led indicating file transfer should turn off after it done


Code

LED Flow Demo Code

# main.py -- put your code here!
leds = [pyb.LED(i) for i in range(1,5)]

sw=pyb.Switch()
def test():
    pyb.LED(1).on()
    pyb.LED(2).on()
    pyb.LED(3).on()
    pyb.LED(4).on()
    pyb.delay(2000)
sw.callback(test)

for l in leds:
    l.off()

n = 0

try:
   while True:
      n = (n + 1) % 4
      leds[n].toggle()
      pyb.delay(50)
finally:
    for l in leds:
        l.off()

REPL Use Guide


  • Must use putty for first time, less easy to get error
  • press CTRL+C to stop or CTRL+D to run program again.
  • get >>> to start.

Futher Usage