From 3381f0bae6f0798b52a3f272ec5c19c7d315dc03 Mon Sep 17 00:00:00 2001 From: Tobias Roeddiger <roeddiger@teco.edu> Date: Fri, 29 Sep 2023 16:13:09 +0200 Subject: [PATCH] Update README.md --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 846327e..ec87515 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,46 @@ To use OpenEarable.js simply integrate the library found under `assets/js/OpenEa <script src="./OpenEarable.js"></script> ``` +### Usage Example +The following example shows how to use the OpenEarable library. + +#### Connect to OpenEarable +```js +const openEarable = new OpenEarable(); + +// Read device identifier once connected +openEarable.bleManager.subscribeOnConnected(async () => { + const deviceId = await earable.readDeviceIdentifier(); + console.log(`Connected to device: ${deviceId}`); +}); + +// Connect to the BLE device +openEarable.bleManager.connect(); +``` + +#### Subscribe to Sensor Data +```js +// Subscribe to the sensor data +openEarable.subscribeOnSensorDataReceived((data) => { + // Process the received IMU data + console.log(data); +}); + +// Enable IMU at 30 Hz +wait sensorManager.writeSensorConfig(0, 30, 0); // 0 sensorId, 30 samplingRate +``` + +#### Play Audio +```js +// Play audio file from microSD card +openEarable.audioPlayer.wavFile(1, "music.wav"); // 1 state (play), music.wav file to play from microSD card +``` + +#### Control RGB LED +```js +// TODO +``` + ## License Distributed under the MIT License. See LICENSE for more information.