Sensors package for pxt-microbit
Set and get NeoPixel LEDs brightness. To use this blocks, an instatiation of NeoPixel strip is needed. Example:
let item: neopixel.Strip = null
item = neopixel.create(DigitalPin.P0, 24, NeoPixelMode.RGB)
sensors.setBrightness(item, 50)
basic.showNumber(sensors.getBrightness(item))
Create a 4-DigitDisplay, set brightness and show number in this display. Example:
let item: grove.TM1637 = null
item = sensors.create4dDisplay(DigitalPin.P0, DigitalPin.P1)
sensors.setBrightness4dDisplay(item, 2)
sensors.showNumber4dDisplay(item, 5555)
On Gesture and Distance Sensor (Ultrasonice Sensor (in cm) from Grove) are also available. Example:
sensors.onGesture(SensorsGroveGesture.Wave, () => {
basic.showString("Hello!")
})
basic.showNumber(sensors.measureInCentimeters(DigitalPin.P0))
Triggers the servo motor in the selected direction and speed (0 to 100%), in pins P13, P14 and P15. Example:
sensors.continuousServoWritePin13(Direction.Right, 100)
Read button status (returns true for pressed and false for unpressed). Example:
if (sensors.isButtonPressed(DigitalPin.P0)) {
basic.showIcon(IconNames.Yes)
} else {
basic.showIcon(IconNames.No)
}
Turn on/off a LED. Example:
input.onButtonPressed(Button.A, () => {
sensors.turnOnOffLed(DigitalPin.P0, OperationStatus.on)
})
input.onButtonPressed(Button.B, () => {
sensors.turnOnOffLed(DigitalPin.P0, OperationStatus.off)
})
Read sensors, like soil moisture, potentiometer, light level and sound sensors. Example:
basic.forever(() => {
if (sensors.getMoistureValue(InitialPins.P0, MoistureSensorRange.dry)) {
basic.showString("Dry Soil")
}
})
Executes a code when a joystic position is detected. Example:
sensors.joystickDirection(InitialPins.P0, InitialPins.P1, JoystickPosition.up, () => {
basic.showString("Up!")
})
MIT
- for PXT/microbit