Difference between revisions of "MP Quick Start"

From ElectroDragon
Jump to navigation Jump to search
(Created page with "== 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...")
 
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
 
  tpybcdc.inf -> Board USB shell driver
 
  tpybcdc.inf -> Board USB shell driver
 
* Drag new main.py file to update code
 
* Drag new main.py file to update code
 +
== LED Flow Demo Code ==
 +
<source lang="python">
 +
# 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()
 +
</source>
 
== REPL ==
 
== REPL ==
 
* Must use putty for first time, less easy to get error
 
* Must use putty for first time, less easy to get error
 
* press CTRL+C to stop or CTRL+D to run program again.
 
* press CTRL+C to stop or CTRL+D to run program again.
 
* get >>> to start.
 
* get >>> to start.
 +
== 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
  
 
[[category: Micropython]]
 
[[category: Micropython]]

Latest revision as of 00:44, 17 June 2020

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

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

  • 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.

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