Skip to content

DFRobot Boson Kit is a set of coding-free electronic building blocks for young inventors, STEM educators and tinkerers

License

Notifications You must be signed in to change notification settings

DFRobot/pxt-DFRobot_bosonKit

Repository files navigation

Boson Kit

DFRobot Boson Kit is a set of modularized electronic building blocks designed for young inventors and STEM educators.Boson platform has more than 50 different modules, including sensors, actuators, logic gates and more.Boson modules are magnetic. They can stick on a whiteboard, fridge, or other magnetic objects In a snap.Each boson module comes with mounting plates that compatible with Lego blocks and screws.

Module Document Address

Basic usage

  • 1.Reads values from rotation encoder and serial prints them.

basic.forever(function () {
    serial.writeValue("rotation:", bosonKit.bosonAnalogRead(AnalogPin.P0, bosonKit.BosonSensorAnalogRead.BosonRotation))
})

  • 2.Reads values from light sensor and serial prints them every second.

basic.forever(function () {
    serial.writeValue("light_intensity:", bosonKit.bosonAnalogRead(AnalogPin.P0, bosonKit.BosonSensorAnalogRead.BosonLightIntensity))
    basic.pause(1000)
})

  • 3.Reads values from steam sensor and serial prints them every second.

   basic.forever(function () {
    serial.writeValue("steam:", bosonKit.bosonAnalogRead(AnalogPin.P0, bosonKit.BosonSensorAnalogRead.BosonSteam))
    basic.pause(1000)
})

  • 4.Reads values from flame sensor and serial prints them every second.
basic.forever(function () {
    serial.writeValue("flame:", bosonKit.bosonAnalogRead(AnalogPin.P0, bosonKit.BosonSensorAnalogRead.BosonFlame))
    basic.pause(1000)
})

  • 5.Reads values from sound sensor and serial prints them every second.

  basic.forever(function () {
    serial.writeValue("sound:", bosonKit.bosonAnalogRead(AnalogPin.P0, bosonKit.BosonSensorAnalogRead.BosonSound))
    basic.pause(1000)
})

  • 6.Reads values from multiple analog sensors simultaneously and serial prints them every second.

basic.forever(function () {
    serial.writeValue("grayscale:", bosonKit.bosonAnalogRead(AnalogPin.P0, bosonKit.BosonSensorAnalogRead.BosonGrayscale))
    serial.writeValue("temp:", bosonKit.bosonAnalogRead(AnalogPin.P1, bosonKit.BosonSensorAnalogRead.BosonTemperature))
    serial.writeValue("soil:", bosonKit.bosonAnalogRead(AnalogPin.P2, bosonKit.BosonSensorAnalogRead.BosonSoilMoisture))
    serial.writeValue("humidity:", bosonKit.bosonAnalogRead(AnalogPin.P3, bosonKit.BosonSensorAnalogRead.BosonHumidity))
    basic.pause(1000)
})

The method above is also applicable to other analog sensors.

  • 7.Reads values of button module and serial prints them.

 basic.forever(function () {
    serial.writeValue("button", bosonKit.bosonDigitalRead(DigitalPin.P0, bosonKit.BosonSensorDigitalRead.BosonPushButton))
})

  • 8.Write high level to P1 to drive the fan on P1.

basic.forever(function () {
    bosonKit.bosonDigitalWrite(DigitalPin.P1, 1, bosonKit.BosonSensorDigitalWrite.BosoFan)
})

  • 9.When the button on pin P0 is pressed, the color LED strip on P1 will be lit up, otherwise, it is off.

basic.forever(function () {
    if (bosonKit.bosonDigitalRead(DigitalPin.P0, bosonKit.BosonSensorDigitalRead.BosonPushButton) == 1) {
        bosonKit.bosonDigitalWrite(DigitalPin.P1, 1, bosonKit.BosonSensorDigitalWrite.BosonBrightLightLed)
    } else {
        bosonKit.bosonDigitalWrite(DigitalPin.P1, 0, bosonKit.BosonSensorDigitalWrite.BosonBrightLightLed)
    }
})

  • 10.Write a value to the fan module on P0 port to drive it to spin.

basic.forever(function () {
    bosonKit.bosonAnalogWrite(AnalogPin.P0, 429, bosonKit.BosonSensorAnalogWrite.BosonFan)
})

  • 11.Rotate the knob module on pin P0; when it's rotated to the maximum value, the bright LED module on pin P8 shows the brightest light.

basic.forever(function () {
    bosonKit.bosonAnalogWrite(AnalogPin.P8, Math.map(bosonKit.bosonAnalogRead(AnalogPin.P0, bosonKit.BosonSensorAnalogRead.BosonRotation), 0, 1023, 0, 1023), bosonKit.BosonSensorAnalogWrite.BosonBrightLightLed)
})

  • 12.Read resting heart rate values and serial prints them.

bosonKit.heartrateInit(DigitalPin.P0)
basic.forever(function () {
    serial.writeValue("heartrate:", bosonKit.heartrateRead())
})

  • 13.Initialize RGB LED strip, and set it as lighting up 7 LEDs and turning off them all after 5s.

bosonKit.m01100184Init(DigitalPin.P0, 7)
bosonKit.m01100184ShowColor(0xff0000)
basic.pause(5000)
bosonKit.m01100184Off()

  • 14.After initializing RGB LED strip, let the 1st and 2nd LEDs show red light, the 3rd and 4th LEDs show green light, and the 5th, 6th and 7th LEDs show blue light.

bosonKit.m01100184Init(DigitalPin.P0, 7)
basic.forever(function () {
    bosonKit.m01100184SetIndexColor(bosonKit.m01100184LedRange(1, 2), 0xff0000)
    bosonKit.m01100184SetIndexColor(bosonKit.m01100184LedRange(3, 4), 0x00ff00)
    bosonKit.m01100184SetIndexColor(bosonKit.m01100184LedRange(5, 7), 0x0000ff)
})

  • 15.Set brightness of RGB LED to 50.

bosonKit.m01100184Init(DigitalPin.P0, 7)
bosonKit.m01100184Brightness(50)
basic.forever(function () {
    bosonKit.m01100184ShowColor(0xff0000)
})

  • 16.Initialize servo angle to 0 degrees, then let servo rotate to the position of 90 degrees.

bosonKit.setServoAngle(AnalogPin.P0, 0)
basic.forever(function () {
    bosonKit.setServoAngle(AnalogPin.P0, 90)
})

License

MIT

Copyright (c) 2020, microbit/micropython Chinese community

Supported targets

  • for PXT/microbit
bosonKit=github:DFRobot/pxt-DFRobot_Boson_Kit

About

DFRobot Boson Kit is a set of coding-free electronic building blocks for young inventors, STEM educators and tinkerers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages