Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arduino Android Blueprints

You're reading from  Arduino Android Blueprints

Product type Book
Published in Dec 2014
Publisher Packt
ISBN-13 9781784390389
Pages 250 pages
Edition 1st Edition
Languages

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 library and the BLE module:

aREST rest = aREST();

// BLE instance
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

We also need to define a variable that will contain the BPM measurements...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}