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 have made sure that the robot is working properly, we can write the final sketch that will receive the commands via Bluetooth. As the sketch shares many similarities with the test sketch, we are only going to see what is added compared to the test sketch. We first need to include more libraries:

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

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

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

We have to create an instance of the BLE module:

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

In the setup() function of the sketch, we initialize the BLE chip:

BTLEserial.begin();

In the loop() function, we check the status of the BLE chip and store it in a variable:

BTLEserial.pollACI();
aci_evt_opcode_t status = BTLEserial.getState();

If...

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}