1 Star 0 Fork 0

DFRobot/pxt-DFRobot_Boson_Kit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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
MIT License Copyright (c) 2021 TgJe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dfrobot/pxt-DFRobot_Boson_Kit.git
git@gitee.com:dfrobot/pxt-DFRobot_Boson_Kit.git
dfrobot
pxt-DFRobot_Boson_Kit
pxt-DFRobot_Boson_Kit
master

搜索帮助