Skip to content

Commit 9bce6e8

Browse files
committed
nicla-system: Add more documentation.
1 parent d399ee3 commit 9bce6e8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

libraries/Nicla_System/examples/NiclaSenseME_BatteryStatus/NiclaSenseME_BatteryStatus.ino

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/*
2+
* This example shows how to use the Nicla Sense ME library to read the battery status and send it over BLE.
3+
*
4+
* When not connected over BLE, the battery status is printed over the serial port every 4 seconds.
5+
* When connected over BLE, the battery status is checked every 4 seconds and sent over BLE if a value has changed.
6+
* That is, when using the notification mechanism in the BatteryMonitor web app, which is the default.
7+
* The BatteryMonitor web app can also be configured to poll the battery status every X seconds.
8+
*
9+
* The LED colors are used to indicate the BLE connection status:
10+
* - Green: Board is ready but no BLE connection has been established yet.
11+
* - Blue: Board is connected over BLE to a device that wants to read the battery status.
12+
* - Red: A device that was previously connected over BLE has disconnected.
13+
*
14+
* Instructions:
15+
* 1. Upload this sketch to your Nicla Sense ME board.
16+
* 2. Open the BatteryMonitor web app (index.html) in a browser that supports Web Bluetooth (Chrome, Edge, Opera, etc.).
17+
* 3. Connect to your Nicla Sense ME board by clicking the "Connect" button.
18+
*
19+
* Initial author: Sebastian Romero @sebromero
20+
*/
21+
122
#include "Nicla_System.h"
223
#include <ArduinoBLE.h>
324

@@ -242,8 +263,10 @@ void setup()
242263

243264
void loop()
244265
{
245-
//BLE.poll(); // Implicit when calling BLE.connected(). Uncomment when only using BLERead
266+
//BLE.poll(); // Implicit when calling BLE.connected(). Uncomment when only using BLERead (polling mechanism)
246267

268+
// Check if a BLE device is connected and handle battery updates
269+
// via the notification mechanism.
247270
if (BLE.connected()) {
248271
bool newBatteryLevelAvailable = updateBatteryLevel();
249272
bool newBatteryStatusAvailable = updateBatteryStatus();

libraries/Nicla_System/extras/BatteryMonitor/app.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* This is a simple example of a web app that connects to an Arduino board
3+
* and reads the battery level and other battery related characteristics.
4+
*
5+
* It uses the Web Bluetooth API to connect to the Arduino board.
6+
*
7+
* Instructions:
8+
* 1. Upload the NiclaSenseME_BatteryStatus sketch to the Arduino board.
9+
* 2. Open the index.html file in a browser that supports the Web Bluetooth API (Chrome, Edge, Opera).
10+
* 3. Click on the Connect button to connect to the Arduino board.
11+
*
12+
* Initial author: Sebastian Romero @sebromero
13+
*/
14+
15+
116
/// UI elements
217
const connectButton = document.getElementById('connect');
318
const batteryLevelElement = document.getElementById('battery-level');

0 commit comments

Comments
 (0)