2017-12-22から1日間の記事一覧

MicroPython メモ 5 / 函数を定義する

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.39-44 函数は def 文で定義する (define、definition の意味)。ブロック内で定義した変数は自動的にブロック内のローカル変数と見なされる (Lua は明示的に local 宣言しない限り…

MicroPython メモ 4 / if, elif, else

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.34-35 「コロン」「インデント」「elif の綴り」に気をつけさえすれば使い方は他の言語と同じ。 from microbit import * while True: if button_a.was_pressed(): display.scroll…

MicroPython メモ 3 / for ループ

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.33-34 REPL で試してみる。 コロンのあとで改行すると以降は自動的にインデントが設定される。 2 行目を入力して改行したところで BackSpace キーを 1 回押せばそれで自動インデ…

MicroPython メモ 2 / while ループ

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.31-32 from microbit import * while True: display.scroll("hello") sleep(5000) display.scroll("bye") sleep(5000) インデントはスペース 4 つが一般的。 display.scroll() の…