Coder Social home page Coder Social logo

pxt-sensors's Introduction

Sensors

Sensors package for pxt-microbit

Basic usage

NeoPixel - Set and Get Brightness

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))

Grove - On Gesture, 4-DigitDisplay and Distance Sensor

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))

Servo Continuous

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)

Get Sensors Status (on/off)

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)
}

Set Sensors Status (on/off)

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)
})

Get Sensors Value

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")
    }
})

Joystick

Executes a code when a joystic position is detected. Example:

sensors.joystickDirection(InitialPins.P0, InitialPins.P1, JoystickPosition.up, () => {
    basic.showString("Up!")
})

License

MIT

Supported targets

  • for PXT/microbit

pxt-sensors's People

Contributors

efk-certi avatar

Stargazers

Nikolay M avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.