Skip to content

Instantly share code, notes, and snippets.

@emceeaich
Last active May 31, 2019 06:56
Show Gist options
  • Save emceeaich/26da6be3ed400b381e8a2cf3e03f33d1 to your computer and use it in GitHub Desktop.
Save emceeaich/26da6be3ed400b381e8a2cf3e03f33d1 to your computer and use it in GitHub Desktop.
Environment Sensor for MicroBit and Pimoroni EnvroBit

Environment Sensor for MicroBit

Requirements

  • BBC Microbit
  • EnviroBit extension
  • Bluetooth extension

Use

  • Buttons

    • A: Temperature in C
    • B: Pressure in in mm
  • Clap once for Temperature

  • Clap twice for Pressure

Bluetooth

Device advertises a URL to this documentation

let t = 0
let claps = 0
input.onButtonPressed(Button.A, function () {
basic.showString("" + `T: ${tm}`)
})
input.onButtonPressed(Button.B, function () {
basic.showString("" + `P: ${p}`)
})
envirobit.onClap(function () {
claps += 1
})
let tm = 0
let p = 0
bluetooth.advertiseUrl(
"https://bit.ly/2HMjRA0",
7,
false
)
control.inBackground(function () {
p = envirobit.getPressure()
tm = envirobit.getTemperature()
})
basic.forever(function () {
t = envirobit.timeSinceLastClap()
if (t > 2000) {
basic.showIcon(IconNames.Asleep)
} else if (t > 500) {
if (claps > 1) {
basic.showString("P: " + p)
} else if (claps == 1) {
basic.showString("T: " + tm)
}
claps = 0
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment