Skip to content

Instantly share code, notes, and snippets.

@baobao
Created August 7, 2020 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/45ff109c8762759ad3739cdd90b7331f to your computer and use it in GitHub Desktop.
Save baobao/45ff109c8762759ad3739cdd90b7331f to your computer and use it in GitHub Desktop.
Serial
// setup serial
serial.setBaudRate(BaudRate.BaudRate115200)
// 0:none, 1:Success, 2:Fail
basic.forever(function ()
{
let str = serial.readString()
if (str.indexOf("1") >= 0) {
basic.showIcon(IconNames.Heart)
basic.pause(1000)
} else if (str.indexOf("2") >= 0) {
basic.showIcon(IconNames.No)
basic.pause(1000)
} else if (str.indexOf("3") >= 0) {
basic.showLeds(`
. # # # .
# . . . #
. . # # .
. . # . .
. . # . .
`)
basic.pause(1000)
} else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
}
})
// debug
input.onButtonPressed(Button.A, function () {
basic.showIcon(IconNames.QuarterNote)
})
input.onButtonPressed(Button.AB, function () {
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment