Skip to content

Instantly share code, notes, and snippets.

@newbornfrontender
Created January 16, 2020 12:38
Show Gist options
  • Save newbornfrontender/325a86efae5c6bd479c0970f29597071 to your computer and use it in GitHub Desktop.
Save newbornfrontender/325a86efae5c6bd479c0970f29597071 to your computer and use it in GitHub Desktop.
microbit - temperature and accelerometer test
const getTemperature = (): number => input.temperature();
const printTemperature = (): void => basic.showNumber(getTemperature())
const showIcon = (name: IconNames): void => basic.showIcon(name)
const isButtonPressed = (button: Button): boolean => input.buttonIsPressed(button)
basic.forever(() => {
const isAPressed = isButtonPressed(Button.A)
const isBPressed = isButtonPressed(Button.B)
if (isAPressed) printTemperature()
if (isBPressed) input.onShake(() => showIcon(IconNames.Heart))
else if (!isBPressed) basic.clearScreen()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment