顯示具有 Micro:bit 標籤的文章。 顯示所有文章
顯示具有 Micro:bit 標籤的文章。 顯示所有文章

2019年8月10日 星期六

4rdp 拼圖抽籤及計時程式

https://4rdp.blogspot.com/2019/08/4rdp.html

# 4rdp puzzle timer

from microbit import *
from random import randint
import utime

shapes = "TIJLOSZTIJLOSZTIJLOSZTIJLOSZTIJLOSZT "
display.show("-")

while True:
    if button_a.was_pressed():
        display.show(" ")
        sleep(100)
        ln = len(shapes)
        if ln == 37:
            t0 = utime.ticks_ms()
        elif ln == 1:
            t1 = utime.ticks_ms()
            break
        r = randint(0,ln-2)
        display.show(shapes[r])
        if r == 0:
            shapes = shapes[1:]
        else:
            shapes = shapes[0:r] + shapes[r+1:]

display.show("=")

while not button_a.was_pressed():
    sleep(1)
else:
    t = (t1 - t0)//1000
    m = t //60
    s = t % 60
    if s < 10:
        s = "0"+str(s)
    else:
        s = str(s)
    display.scroll(str(m)+":"+s,loop=True)

2019年7月29日 星期一

4rdp 拼圖抽籤程式

https://4rdp.blogspot.com/2019/07/4rdp_29.html

from microbit import *
from random import randint

shapes = "TIJLOSZTIJLOSZTIJLOSZTIJLOSZTIJLOSZT "
display.show("-")

while True:
    if button_a.was_pressed():
        display.show(" ")
        sleep(100)
        ln = len(shapes)
        if ln == 1:
            break
        r = randint(0,ln-2)
        display.show(shapes[r])
        if r == 0:
            shapes = shapes[1:]
        else:
            shapes = shapes[0:r] + shapes[r+1:]

display.show("=")

2019年7月20日 星期六

Micro:bit 韌體與 WebUSB 驅動程式更新

https://4rdp.blogspot.com/2019/07/microbit-webusb.html

近日買入 Micro:bit 開始研究,第一個想設計的功能就是拼圖抽籤機,在 Micro:bit 上執行,以隨機亂數抽取拼塊,按一次 A 鍵就顯示一片拼塊,按 36 次就結束,我立即以 Python 寫個程式試看看,發現 Micro:bit 系統有 bug!! 陣列中的最後一個項目,竟然沒辦法取用!

我的直覺應該是 Micro:bit 內的韌體是舊版,須要更新,因此立即上網查詢相關資料,首先查到台灣程式教育協進會 http://k12.camdemy.com/media/18959 的影片,可從 github 下載最新韌體 https://github.com/ARMmbed/DAPLink/releases。不過更新之後仍然無法使用 DAPLink,也就是執行 Python 時可以協助除錯的功能。


所以還要再去安裝電腦端驅動程式,https://os.mbed.com/handbook/Windows-serial-configuration
可以安裝 mbed Serial Port。