O'Reilly logo

Arduino Android Blueprints by Stefan Buttigieg, Marco Schwartz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing the Arduino sketch

Now that we are sure that the sensor is working correctly, we can write the final Arduino sketch for this chapter. This sketch will perform the BPM measurements as before, and will also expose the BPM variable via the aREST API so that the measurements can be accessed via Bluetooth. As the sketch is really similar to the test sketch, we will only detail the changes here.

The sketch starts by importing the required libraries:

#include <SPI.h>
#include "Adafruit_BLE_UART.h"
#include <aREST.h>

We also define the pins on which the BLE module is connected:

#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2     // This should be an interrupt pin, on Uno thats #2 or #3
#define ADAFRUITBLE_RST 9

Then we create an instance of the aREST ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required