Arduino For Kids Young and Old by Daniel Milligan

Page 115

connected g_pBTModule->begin(BT_COMM_SPEED, true, "ArduinoBT", BT_PIN_CODE); // do we need to block on this? g_connectionState = RestoreDeviceAddress; } break; case RestoreDeviceAddress: { if (StoredData.valid != 0) { pRemoteAddress = (char *)&StoredData.bt_address[0]; g_connectionState = DeviceDiscovered; } else { pRemoteAddress = NULL; g_connectionState = DiscoveringDevice; } } break; case DiscoveringDevice: { Serial.println("Discovering devices..."); // discover our device, do not block, we will come back to try again if (g_pBTModule->discoverDevice(false) == true) { g_connectionState = DeviceDiscovered; } } break; case DeviceDiscovered: { Serial.println("Connecting to device..."); if (g_pBTModule->connectToDevice(pRemoteAddress, true) == true) { g_connectionState = ActiveCommunications; digitalWrite(BT_CONNECTED_STATUS_PIN, HIGH); // we have a connection // Update eeprom data if (StoredData.valid == 0) { WriteInteger((char *)&StoredData.valid - (char *)&StoredData.signature, 1); // it is now valid g_pBTModule->getRemoteAddress((char *)&StoredData.bt_address[0]); WriteBytes((char *)&StoredData.bt_address[0] - (char *)&StoredData.signature, (byte *)&StoredData.bt_address[0], MAX_BT_ADDRESS); } } } break;


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