Microsoft Small Basic

Program Listing: HQX644
' Python Console for micro:bit
' Copyright © 2017 Nonki Takahashi. The MIT License.
' Last update 2017-08-24

TextWindow.Title = "Small Basic Microbit Interface"
Init()
While ("True")
key = TextWindow.ReadKey()
If key <> "" Then
LDCommPort.TXString(key)
Else
Program.Delay(10)
EndIf
EndWhile

Sub Init
LF = Text.GetCharacter(10)
status = LDCommPort.OpenPort("COM4", 115200)
LDCommPort.SetDataBits(8)
LDCommPort.SetParity("None")
LDCommPort.SetStopBits("One")
LDCommPort.SetEncoding("Ascii")
LDCommPort.DataReceived = OnDataReceived
EndSub

Sub OnDataReceived
dataIn = LDCommPort.RXAll()
TextWindow.Write(dataIn)
EndSub