Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srs/pxt-bitbot
A BitBot package for pxt-microbit.
https://github.com/srs/pxt-bitbot
Last synced: 3 months ago
JSON representation
A BitBot package for pxt-microbit.
- Host: GitHub
- URL: https://github.com/srs/pxt-bitbot
- Owner: srs
- License: apache-2.0
- Created: 2017-03-31T13:58:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-03T09:54:46.000Z (over 5 years ago)
- Last Synced: 2024-01-21T05:18:02.901Z (5 months ago)
- Language: TypeScript
- Size: 24.4 KB
- Stars: 25
- Watchers: 3
- Forks: 14
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Lists
- awesome-microbit-zh - BitBot - BitBot(使用microbit控制的一款小车)的pxt驱动. (编程 / JavaScript 和 MakeCode)
README
# BitBot Package for Microsoft PXT
[![Build Status](https://travis-ci.org/srs/pxt-bitbot.svg?branch=master)](https://travis-ci.org/srs/pxt-bitbot)
[![GitHub Tag](https://img.shields.io/github/tag/srs/pxt-bitbot.svg)]()This library provides a Microsoft PXT package for BitBot, see
https://4tronix.co.uk/bitbot/.## Driving the motor
Use `bitbot.motor(..)` to drive motor either forward or reverse. The value
indicates speed and is between `-1023` to `1023`. Minus indicates reverse.```blocks
// Drive 1000 ms forward
bitbot.motor(BBMotor.All, 1023);
basic.pause(1000);// Drive 1000 ms reverse
bitbot.motor(BBMotor.All, -1023);
basic.pause(1000);// Drive 1000 ms forward on left and reverse on right
bitbot.motor(BBMotor.Left, 1023);
bitbot.motor(BBMotor.Right, -1023);
basic.pause(1000);
```## Buzz sound
To use the buzzer, just use `bitbot.buzz(..)` function with either `1`
(sound) or `0` (no-sound).```blocks
// Buzz for 100 ms
bitbot.buzz(1);
basic.pause(100);
bitbot.buzz(0);
```## Read line sensor
The BitBot has two line-sensors: left and right. To read the value of the
sensors, use `bitbot.readLine(..)` function.```blocks
// Read left and right line sensor
let left = bitbot.readLine(BBLineSensor.Left);
let right = bitbot.readLine(BBLineSensor.Right);
```## Read light sensor
Light sensors can be read using `bitbot.readLight(..)` function.
```blocks
// Read left and right light sensor
let left = bitbot.readLight(BBLightSensor.Left);
let right = bitbot.readLight(BBLightSensor.Right);
```## Read sonar value
If you have mounted the optional sonar sensor for the BitBot you can
also use the `bitbot.sonar(..)` function to read the distance to obstacles.```blocks
// Read sonar values
let v1 = bitbot.sonar(BBPingUnit.MicroSeconds);
let v2 = bitbot.sonar(BBPingUnit.Centimeters);
let v3 = bitbot.sonar(BBPingUnit.Inches);
```## NeoPixel helpers
The BitBot has 12 NeoPixels mounted. This library defines some helpers
for using the NeoPixels.```blocks
// Show all leds
bitbot.neoSetColor(neopixel.colors(NeoPixelColors.Red));
bitbot.neoShow();// Clear all leds
bitbot.neoClear();
bitbot.neoShow();// Show led at position 1
bitbot.neoSetPixelColor(0, neopixel.colors(NeoPixelColors.Red));
bitbot.neoShow();// Show led rainbow
bitbot.neoRainbow();
bitbot.neoShow();// Show led rainbow and shift
bitbot.neoRainbow();
bitbot.neoShift();
bitbot.neoShow();// Show led rainbow and rotate
bitbot.neoRainbow();
bitbot.neoRotate();
bitbot.neoShow();// Set brightness of leds
bitbot.neoBrightness(100);
bitbot.neoShow();// Use neo() variable
bitbot.neo().clear();
bitbot.neo().show();
```## Supported targets
* for PXT/microbit
## License
Apache 2.0