micro:bit & MicroPython
単純法 #include "MicroBit.h" MicroBit uBit; uint8_t AinB(ManagedString A, ManagedString B){ int ALen = A.length(); int BLen = B.length(); int difLen = BLen - ALen; // 文字列Bを左(i)から文字列Aの文字数ぶん(ALen)ずつ順番に見ていって、 uint8_…
MicroPython でプログラミングした場合の最速パルスを見てみる。 周波数は約 7 kHz であった。ディレイを挟んでいないのにデューティは 50% にならない。 from microbit import * while True: pin0.write_digital(1) pin0.write_digital(0)
参考: The Official BBC micro:bit User Guide, pp.180-182 micro:bit 側で print() 函数を実行すれば micro:bit から PC へ USB ケーブル経由で簡単にテキストが送れる。 ただの UART なのでターミナルでも同じように受信できる。 うまく通信できない場合は…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.135 mu エディターの REPL ペインに打ち込んだテキストを micro:bit のディスプレイに表示する。 ただの UART なので、両者で設定を合わせれば tera term などのターミナルでも同…
JavaScript 用のオンラインエディターには micro:bit 本体のエミュレーターがついているが MicroPython の場合はオンラインエディターにも mu エディターにも micro:bit 本体のエミュレーターはない。 非公式には Create with code がある。ここにコードを入…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.119 USB ポートから micro:bit に電力を供給する場合は、オンボードレギュレーターによって 3.3 V が生成される。このレギュレーターは 最大 120 mA 出力できる。したがって假に …
参考: Programming the BBC Micro:bit: Getting Started With MicroPython, pp.115-119 Prototyping Lab 第2版 ―「作りながら考える」ためのArduino実践レシピ (Make: PROJECTS), pp.108-111 GND ~ VCC の範囲の電圧が 0 ~ 1023 (10 ビット) に AD 変換さ…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.115 from microbit import * while True: if pin0.read_digital(): display.show("H") else: display.show("L") ――――――――――――――――――――――――――――――― オンボードボタンの接続は下の…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p. 113-115 アナログ出力といっても Arduino と同じく PWM 出力である。 from microbit import * brightness = 0 step = 100 def constrain(var, MIN = 0, MAX = 1023): return max…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, pp.112-113 ピン 1 本につき 5 mA まで取り出せるとの由。 Arduino は pinMode(~, OUTPUT); のように input か output かを事前にセットしなければならないが、micro:bit は write…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.108 オンボード LED をまったく点灯しない場合は約 19 mA。 オンボード LED を 1 個点灯するごとに約 1 mA 増。 BLE を使うとさらに約 10 mA 増。USB コネクターから電力を供給す…
参考: Programming the BBC micro:bit: Getting Started with MicroPython (English Edition), pp.102-103 micro:bit 本体だけでできることはこれでだいたい終わり。 from microbit import * while True: if pin2.is_touched(): display.show(Image.HEART) s…
参考: micro:bitではじめるプログラミング ―親子で学べるプログラミングとエレクトロニクス (Make:PROJECTS), pp.71-74オンボード LED を照度センサーとして使う。 今のところ MicroPython ではプログラミングできない。下のコードの意味もわからない。 basi…
ただし取得されるのはマイクロプロセッサー内部の温度センサーの値である。単位は摂氏。
参考: Programming the BBC micro:bit: Getting Started with MicroPython (English Edition), pp.99-102 micro:bitではじめるプログラミング ―親子で学べるプログラミングとエレクトロニクス (Make:PROJECTS), pp.54-59 使用している磁気センサーは MAG3110…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.96-99 accelerometer.get_values()3 軸を同時に取得する。 accelerometer.get_x(), accelerometer.get_y(), accelerometer.get_z()軸ごとに取得する。 from microbit import * wh…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.96 micro:bitではじめるプログラミング ―親子で学べるプログラミングとエレクトロニクス (Make:PROJECTS), p.45-48 使用しているチップは MMA8653FC。 from microbit import * fr…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.95 is_pressed()ボタンが押された場合に True を返す。それ以外の場合は False を返す。 was_pressed()micro:bit の起動後か was_pressed() の呼び出し後かいずれかにボタンが押…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.89-91 Image クラスを使って個々のドット絵をインスタンス化し、それをリストに格納して display.show() の引数に取れば、各絵文字が順番に表示される (Image.ALL_CLOCKS などは…
参考: Programming the BBC Micro:bit: Getting Started With MicroPython, pp.88-89 例 (たぶんクリスマスツリー): ほかにもたくさんある (Image — BBC micro:bit MicroPython 1.0.1 documentation)。
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p. 88 引数は文字列のみ。 オプションパラメーターは display.scroll() と同じ。 display.show("abcdefg") のように文字列を引数に取ると、delay パラメーター (デフォルト値は 400…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.87 display.scroll("hello, world")指定の文字列を 1 回だけスクロール表示する。スクロール中は他の処理を受け付けない。Ctrl + C で中断できる。 display.scroll("hello, world…
参考: Programming the BBC Micro:bit: Getting Started With MicroPython, pp.85-86 個々の LED を操作するときは display.set_pixel(x 座標, y 座標, 明るさ) という構文で指定する。座標は左上を (0, 0) とする。明るさは 0 ~ 9 で指定する。 from micro…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.80-83 (たとえば display.scroll("hello、world") は、display というインスタンスの親である何らかのクラスに属している scroll() メソッドを実行するコマンドである) 下のモジ…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.78-80 プログラムでモジュールを利用するためには、そのモジュールが micro:bit 上に存在していなければならないが、假に今モジュールが micro:bit 上に存在していたとしても、プ…
参考: Programming the BBC Micro:bit: Getting Started With MicroPython, pp.75-76 これまでに出てきた button_a や display は何らかのクラスのインスタンスである。どのクラスのインスタンスであるかは type() で確認できる。 ひとつのクラスは属性とメ…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p73-75 モジュールの中身を確認する。 from モジュール名 import * という構文でモジュールの中身を全部インポートする。 下のようにしてもモジュールの中身全部がインポートされる…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.68-69 これだとインデックスが 5 を超えたところでエラーが出てプログラムが停止してしまう (Lua だと、存在しない要素を参照したときは nil が返ってくる)。 list = [0, 1, 2, 3…
参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.69-71 from microbit import * with open("test.txt", "w") as sute: sute.write("ABC") with open("test.txt") as sute: message = sute.read() while True: display.scroll(mes…