<commit_before># microBit.js
A javascript library to interact with BBC micro:bit using web bluetooth API.

## Usage

To use the library, download and upload [this firmware](https://drive.google.com/uc?id=0B2Ud_NaMFsQSdm1BMVMtN3F4a3c&export=download) on your BBC micro:bit board.

The firmware was produced by [bittysoftware](http://www.bittysoftware.com/downloads.html).

Keep in mind that web bluetooth API are still experimental and your OS and browser might not support the feature. Read more about this [here](https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web).

This Library allows you to read and write the values of all the BLEcharacteristic exposed by the microBit board using simplified API's.

For more info about all micro:bit ble services please refer to the [official documentation](https://lancaster-university.github.io/microbit-docs/ble/profile/).

The example folder provided contains several examples for interacting with the device.

## Constructor

- `microBit=new uBit()`

## Properties

- `microBit.connected`

## Functions


- `microBit.searchDevice()`

  Search for ble devices in range.


- `microBit.setButtonACallback(callbackFunction)`

  Register a callback function to be invoked when Button A is pressed.

  example:
  ```
  microBit.setButtonACallback(function(){
    console.log("buttonA pressed");
  });
  ```

- `microBit.setButtonBCallback(callbackFunction)`

  Register a callback function to be invoked when Button B is pressed.

  example:
  ```
  microBit.setButtonBCallback(function(){
    console.log("buttonB pressed");
  });
  ```

- `microBit.onConnect(callbackFunction)`

  Register a callback function invoked when the microBit connects

  example:
  ```
  microBit.onConnect(function(){
    console.log("connected");
  });
  ```

- `microBit.onDisconnect(callbackFunction)`

  Register a callback function invoked when the microBit disconnects

  example:
  ```
  microBit.onDisconnect(function(){
    console.log("disconnected");
  });
  ```

- `microBit.onBleNotify(callbackFunction)`

  Register a callback function invoked every time the value of characteristic changes and it is notified by the device.

  example:
  ```
  microBit.onBleNotify(function(){
    document.getElementById("buttonA").innerHTML=microBit.getButtonA();
  }
  ```

- `microBit.writeMatrixIcon(icon)`

  Updates the led matrix on the microbit.
  The `icon` passed to the function must be 5x5 matrix.
  0=led off;
  1=led on;

  example:
  ```
  var ledMatrix = [
    ['0', '0', '0', '0', '0'],
    ['0', '1', '0', '1', '0'],
    ['0', '0', '0', '0', '0'],
    ['1', '0', '0', '0', '1'],
    ['0', '1', '1', '1', '0']
  ]

  microBit.writeMatrixIcon(ledMatrix);

  ```

- `microBit.writeMatrixText(text)`

  Updates the led matrix of the microbit with a scrolling text.

  example:
  ```
  microBit.writeMatrixText("ciao microBit")
  ```

- `writeMatrixTextSpeed(speed)`

  set the speed of the scrolling text on the matrix
  example:
  ```
  microBit.writeMatrixTextSpeed(10)
  ```

- `microBit.getAccelerometer()`

  Returns the value of the accelerometer as a object.

  example:
  ```
  acceleration=microBit.getAccelerometer();
  acc_x=acceleration.x;
  acc_y=acceleration.y;
  acc_z=acceleration.z;

  ```

- `microBit.getTemperature()`

  Returns the value of the temperature measured on the processor in celsius.

  example:
  ```
  temperature=microBit.getTemperature();

  ```


- `microBit.getBearing()`

  Returns the value of magnetometer bearing from 0 to 360.
  0= pointing nord

  example:
  ```
  bearing=microBit.getBearing();

  ```

## Examples
Check the examples folder for working examples.

### basic example
Connect your microbit to a webpage, visualize the data and change the animations on the led matrix
[try it here](https://antefact.github.io/microBit.js/examples/basic/)

### p5.js example
Learn how to interact with the microbit from a p5.js sketch and control your character on the screen
try it here<commit_msg>minor fixes to readme<commit_after># microBit.js
A javascript library to interact with BBC micro:bit using web bluetooth API.

## Usage

To use the library, download and upload [this firmware](https://drive.google.com/uc?id=0B2Ud_NaMFsQSdm1BMVMtN3F4a3c&export=download) on your BBC micro:bit board.

The firmware was produced by [bittysoftware](http://www.bittysoftware.com/downloads.html).

Keep in mind that web bluetooth API are still experimental and your OS and browser might not support the feature. Read more about this [here](https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web).

This Library allows you to read and write the values of all the BLEcharacteristic exposed by the microBit board using simplified API's.

For more info about all micro:bit ble services please refer to the [official documentation](https://lancaster-university.github.io/microbit-docs/ble/profile/).

The example folder provided contains several examples for interacting with the device.

## Constructor

- `microBit=new uBit()`

## Properties

- `microBit.connected`

## Functions


- `microBit.searchDevice()`

  Search for ble devices in range.


- `microBit.setButtonACallback(callbackFunction)`

  Register a callback function to be invoked when Button A is pressed.

  example:
  ```
  microBit.setButtonACallback(function(){
    console.log("buttonA pressed");
  });
  ```

- `microBit.setButtonBCallback(callbackFunction)`

  Register a callback function to be invoked when Button B is pressed.

  example:
  ```
  microBit.setButtonBCallback(function(){
    console.log("buttonB pressed");
  });
  ```

- `microBit.onConnect(callbackFunction)`

  Register a callback function invoked when the microBit connects

  example:
  ```
  microBit.onConnect(function(){
    console.log("connected");
  });
  ```

- `microBit.onDisconnect(callbackFunction)`

  Register a callback function invoked when the microBit disconnects

  example:
  ```
  microBit.onDisconnect(function(){
    console.log("disconnected");
  });
  ```

- `microBit.onBleNotify(callbackFunction)`

  Register a callback function invoked every time the value of characteristic changes and it is notified by the device.

  example:
  ```
  microBit.onBleNotify(function(){
    document.getElementById("buttonA").innerHTML=microBit.getButtonA();
  }
  ```

- `microBit.writeMatrixIcon(icon)`

  Updates the led matrix on the microbit.
  The `icon` passed to the function must be 5x5 matrix.
  0=led off;
  1=led on;

  example:
  ```
  var ledMatrix = [
    ['0', '0', '0', '0', '0'],
    ['0', '1', '0', '1', '0'],
    ['0', '0', '0', '0', '0'],
    ['1', '0', '0', '0', '1'],
    ['0', '1', '1', '1', '0']
  ]

  microBit.writeMatrixIcon(ledMatrix);

  ```

- `microBit.writeMatrixText(text)`

  Updates the led matrix of the microbit with a scrolling text.

  example:
  ```
  microBit.writeMatrixText("ciao microBit")
  ```

- `writeMatrixTextSpeed(speed)`

  set the speed of the scrolling text on the matrix
  example:
  ```
  microBit.writeMatrixTextSpeed(10)
  ```

- `microBit.getAccelerometer()`

  Returns the value of the accelerometer as a object.

  example:
  ```
  acceleration=microBit.getAccelerometer();
  acc_x=acceleration.x;
  acc_y=acceleration.y;
  acc_z=acceleration.z;

  ```

- `microBit.getTemperature()`

  Returns the value of the temperature measured on the processor in celsius.

  example:
  ```
  temperature=microBit.getTemperature();

  ```


- `microBit.getBearing()`

  Returns the value of magnetometer bearing from 0 to 360.
  0= pointing nord

  example:
  ```
  bearing=microBit.getBearing();

  ```

## Examples
Check the examples folder for working examples.

### Basic example
Connect your microbit to a webpage, visualize the data and change the animations on the led matrix.

[Try it here](https://antefact.github.io/microBit.js/examples/basic/)

### p5.js example
Learn how to interact with the microbit from a p5.js sketch and control your character on the screen.

[Try it here](https://antefact.github.io/microBit.js/examples/basic/)
{'fraction_non_alphanumeric': 0.12150457807473397, 'fraction_numerical': 0.012373174956693888, 'mean_word_length': 4.10612760581175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 9, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4054473', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2461, 'n_words': 766}