Arduino For Kids Young and Old by Daniel Milligan

Page 110

*/ #include <stdio.h> #include <EEPROM.h> #include <SoftwareSerial.h> #include <btmodule.h> SeeedStudio BT module

// // // //

sprintf storage of connection data communication between BT module and arduino arduino library for communicating with the

// Status pin for onboard led #define BT_CONNECTED_STATUS_PIN

13

// The BT shield can use two digital pins for the serial communications from D0 - D7 #define #define #define #define

BT_COMM_SPEED 38400 BT_PIN_CODE 1234 BT_RX_PIN 6 BT_TX_PIN 7

#define BT_CONNECTED_PIN 1 // analog pin // EEPROM SIGNATURE const long signature = 0xACED; // some non-arbritary value #define MAX_BT_ADDRESS 32 /* Structures used in this sketch */ typedef struct { long signature; // data is only valid when 0xACED is stored here. int valid; // 0 if not valid, non-zero if valid byte bt_address[MAX_BT_ADDRESS]; // bluetooth address of previously discovered device(s) } EE_Structure;

// State machine for bluetooth communications enum StateMachine { Initialize = 0, // if we store the device addr, we can jump to connecting RestoreDeviceAddress, DiscoveringDevice, DeviceDiscovered, // once discovered, we can reconnect without all of the setup ConnectingToDevice, ActiveCommunications, ErrorState, EndStates }; /*


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.